Skip to content

Commit

Permalink
fix missing phrase resetting in benches
Browse files Browse the repository at this point in the history
  • Loading branch information
emuell committed Jul 1, 2024
1 parent 3360be2 commit 50681fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
16 changes: 10 additions & 6 deletions benches/benchmarks/rhythm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ pub fn clone(c: &mut Criterion) {
let phrase = create_phrase();
group.bench_function("Clone", |b| {
b.iter(|| {
black_box(phrase.clone());
let mut phrase = black_box(phrase.clone());
phrase.reset();
})
});
group.finish();
Expand All @@ -167,6 +168,7 @@ pub fn run(c: &mut Criterion) {
b.iter(|| {
let sample_time = SampleTime::MAX;
let mut phrase = phrase.clone();
phrase.reset();
let mut num_events = 0;
while let Some(event) = phrase.run_until_time(sample_time) {
black_box(event);
Expand All @@ -183,15 +185,17 @@ pub fn run(c: &mut Criterion) {
pub fn seek(c: &mut Criterion) {
let mut group = c.benchmark_group("Rust Phrase");
let phrase = create_phrase();
let samples_per_sec = phrase.time_base().samples_per_sec as SampleTime;
let seek_counts = 60 * 30;
let samples_per_sec = phrase.time_base().samples_per_sec;
let seek_step = 10;
let seek_time = 60 * 60;
group.bench_function("Seek", |b| {
b.iter(|| {
let mut phrase = phrase.clone();
let mut sample_time = samples_per_sec;
while sample_time <= seek_counts * samples_per_sec {
phrase.reset();
let mut sample_time = samples_per_sec as SampleTime;
while sample_time < (seek_time * samples_per_sec) as SampleTime {
phrase.seek_until_time(sample_time);
sample_time += samples_per_sec;
sample_time += seek_step * samples_per_sec as SampleTime;
}
})
});
Expand Down
12 changes: 8 additions & 4 deletions benches/benchmarks/scripted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ pub fn clone(c: &mut Criterion) {
let phrase = create_phrase();
group.bench_function("Clone", |b| {
b.iter(|| {
black_box(phrase.clone());
let mut phrase = black_box(phrase.clone());
phrase.reset();
})
});
group.finish();
Expand All @@ -158,6 +159,7 @@ pub fn run(c: &mut Criterion) {
b.iter(|| {
let sample_time = SampleTime::MAX;
let mut phrase = phrase.clone();
phrase.reset();
let mut num_events = 0;
while let Some(event) = phrase.run_until_time(sample_time) {
black_box(event);
Expand All @@ -175,14 +177,16 @@ pub fn seek(c: &mut Criterion) {
let mut group = c.benchmark_group("Scripted Phrase");
let phrase = create_phrase();
let samples_per_sec = phrase.time_base().samples_per_sec;
let seek_counts = 60 * 30;
let seek_step = 10;
let seek_time = 60 * 60;
group.bench_function("Seek", |b| {
b.iter(|| {
let mut phrase = phrase.clone();
phrase.reset();
let mut sample_time = samples_per_sec as SampleTime;
while sample_time < (seek_counts * samples_per_sec) as SampleTime {
while sample_time < (seek_time * samples_per_sec) as SampleTime {
phrase.seek_until_time(sample_time);
sample_time += samples_per_sec as SampleTime;
sample_time += seek_step * samples_per_sec as SampleTime;
}
})
});
Expand Down

0 comments on commit 50681fa

Please sign in to comment.