-
Notifications
You must be signed in to change notification settings - Fork 45
/
benchmark.rs
138 lines (122 loc) · 3.98 KB
/
benchmark.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use fundsp::hacker32::*;
fn sine_bench(_dummy: usize) -> Wave {
Wave::render(
44100.0,
1.0,
&mut (sumi::<U100, _, _>(|i| sine_hz(100.0 * (i + 1) as f32))),
)
}
fn resynth_bench(_dummy: usize) -> Wave {
Wave::render(
44100.0,
1.0,
&mut (noise()
>> resynth::<U1, U1, _>(1024, |fft| {
for i in 0..fft.bins() {
fft.set(0, i, fft.at(0, i));
}
})),
)
}
#[allow(clippy::precedence)]
fn pass_bench(_dummy: usize) -> Wave {
Wave::render(
44100.0,
1.0,
&mut (dc((1.0, 2.0)) * 2.0 >> pass() + pass() >> pass()),
)
}
#[allow(clippy::precedence)]
fn netpass_bench(_dummy: usize) -> Wave {
let x = Net::wrap(Box::new(dc((1.0, 2.0))));
let y = Net::wrap(Box::new(pass()));
Wave::render(44100.0, 1.0, &mut (x * 2.0 >> pass() + y >> pass()))
}
fn wavetable_bench(_dummy: usize) -> Wave {
Wave::render(44100.0, 1.0, &mut (saw_hz(110.0)))
}
fn envelope_bench(_dummy: usize) -> Wave {
Wave::render(
44100.0,
1.0,
&mut (noise() * envelope(|t| (-t).exp() * sin_hz(1.0, t))),
)
}
fn oversample_bench(_dummy: usize) -> Wave {
Wave::render(44100.0, 1.0, &mut (noise() >> oversample(pass())))
}
fn chorus_bench(_dummy: usize) -> Wave {
Wave::render(44100.0, 1.0, &mut (noise() >> chorus(0, 0.015, 0.005, 0.5)))
}
fn equalizer_bench(_dummy: usize) -> Wave {
Wave::render(
44100.0,
1.0,
&mut (noise()
>> pipei::<U10, _, _>(|i| bell_hz(1000.0 + 1000.0 * i as f32, 1.0, db_amp(3.0)))),
)
}
fn reverb_bench(_dummy: usize) -> Wave {
Wave::render(
44100.0,
1.0,
&mut ((noise() | noise()) >> reverb_stereo(10.0, 1.0, 0.5)),
)
}
fn limiter_bench(_dummy: usize) -> Wave {
Wave::render(44100.0, 1.0, &mut (noise() >> limiter(0.1, 1.0)))
}
fn phaser_bench(_dummy: usize) -> Wave {
Wave::render(
44100.0,
1.0,
&mut (noise() >> phaser(0.5, |t| sin_hz(0.1, t) * 0.5 + 0.5)),
)
}
fn lowpass_bench(_dummy: usize) -> Wave {
Wave::render(
44100.0,
1.0,
&mut ((noise()
| lfo(|t| {
(
xerp11(1000.0, 10000.0, sin_hz(1.0, t)),
xerp11(1.0, 2.0, sin_hz(2.0, t)),
)
}))
>> lowpass().subsample(1)),
)
}
fn lowpass16_bench(_dummy: usize) -> Wave {
Wave::render(
44100.0,
1.0,
&mut ((noise()
| lfo(|t| {
(
xerp11(1000.0, 10000.0, sin_hz(1.0, t)),
xerp11(1.0, 2.0, sin_hz(2.0, t)),
)
}))
>> lowpass().subsample(16)),
)
}
fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("netpass", |b| b.iter(|| netpass_bench(black_box(0))));
c.bench_function("sine", |b| b.iter(|| sine_bench(black_box(0))));
c.bench_function("resynth", |b| b.iter(|| resynth_bench(black_box(0))));
c.bench_function("pass", |b| b.iter(|| pass_bench(black_box(0))));
c.bench_function("wavetable", |b| b.iter(|| wavetable_bench(black_box(0))));
c.bench_function("envelope", |b| b.iter(|| envelope_bench(black_box(0))));
c.bench_function("oversample", |b| b.iter(|| oversample_bench(black_box(0))));
c.bench_function("chorus", |b| b.iter(|| chorus_bench(black_box(0))));
c.bench_function("equalizer", |b| b.iter(|| equalizer_bench(black_box(0))));
c.bench_function("reverb", |b| b.iter(|| reverb_bench(black_box(0))));
c.bench_function("limiter", |b| b.iter(|| limiter_bench(black_box(0))));
c.bench_function("phaser", |b| b.iter(|| phaser_bench(black_box(0))));
c.bench_function("lowpass", |b| b.iter(|| lowpass_bench(black_box(0))));
c.bench_function("lowpass16", |b| b.iter(|| lowpass16_bench(black_box(0))));
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);