diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2017-07-12 20:35:09 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2017-07-12 20:35:09 +0200 |
commit | 73e106a45cd62508ef4bf163479d79ea6339f569 (patch) | |
tree | cefc2475b16f5edc4cebcd522da1bc03ef1ef39f | |
parent | 19ad6abf0933d3e3e5b1b3fa693676c47bb07be9 (diff) |
Added benchmark for finding fundamental with correlation
-rw-r--r-- | Cargo.lock | 7 | ||||
-rw-r--r-- | Cargo.toml | 5 | ||||
-rw-r--r-- | benches/transforms.rs | 35 |
3 files changed, 47 insertions, 0 deletions
@@ -2,6 +2,7 @@ name = "rusty_microphone" version = "0.1.0" dependencies = [ + "bencher 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "cairo-rs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "gtk 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "portaudio 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -20,6 +21,11 @@ dependencies = [ ] [[package]] +name = "bencher" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "bitflags" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -288,6 +294,7 @@ dependencies = [ [metadata] "checksum atk-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9d3dd4937c8c40a0b5184d7810772d44cd3d4afdca711b8878c7f14b3f8ef80f" +"checksum bencher 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1938914a389928f8c2cc0aec747380e0b2b854094710e7d03f8eb3762aa7f7a2" "checksum bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dead7461c1127cf637931a1e50934eb6eee8bff2f74433ac7909e9afcee04a3" "checksum bitflags 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4f67931368edf3a9a51d29886d245f1c3db2f1ef0dcc9e35ff70341b78c10d23" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" @@ -7,3 +7,8 @@ authors = ["Justin Worthe <justin.worthe@gmail.com>"] portaudio = "0.7.0" gtk = "0.1.1" cairo-rs = "0.1.1" +bencher = "0.1.2" + +[[bench]] +name = "transforms" +harness = false
\ No newline at end of file diff --git a/benches/transforms.rs b/benches/transforms.rs new file mode 100644 index 0000000..3a4b906 --- /dev/null +++ b/benches/transforms.rs @@ -0,0 +1,35 @@ +#[macro_use] +extern crate bencher; + +extern crate rusty_microphone; + +use bencher::Bencher; + +use std::f32::consts::PI; + +const SAMPLE_RATE: f32 = 44100.0; +const FRAMES: usize = 1024; + + +fn sin_arg(f: f32, t: f32, phase: f32) -> f32 { + 2.0 as f32 * PI * f * t + phase +} + +fn sample_sinusoud(amplitude: f32, frequency: f32, phase: f32) -> Vec<f32> { + (0..FRAMES) + .map(|x| { + let t = x as f32 / SAMPLE_RATE; + sin_arg(frequency, t, phase).sin() * amplitude + }).collect() +} + +fn bench_correlation_on_sine_wave(b: &mut Bencher) { + let frequency = 440.0 as f32; //concert A + let samples = sample_sinusoud(1.0, frequency, 0.0); + + b.iter(|| { + rusty_microphone::transforms::find_fundamental_frequency_correlation(&samples, SAMPLE_RATE) + }) +} +benchmark_group!(transforms, bench_correlation_on_sine_wave); +benchmark_main!(transforms); |