Skip to content

Commit

Permalink
Fix benchmarks accidentally re-using the same database
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Jan 4, 2025
1 parent 32bd57c commit 418e6ea
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions benches/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ fn mutating_inputs(c: &mut Criterion) {
codspeed_criterion_compat::measurement::WallTime,
> = c.benchmark_group("Mutating Inputs");

let mut db = salsa::DatabaseImpl::default();

for n in &[10, 20, 30] {
let mut db = salsa::DatabaseImpl::default();
let base_string = "hello, world!".to_owned();
let base_len = base_string.len();

Expand Down Expand Up @@ -57,28 +56,30 @@ fn inputs(c: &mut Criterion) {
> = c.benchmark_group("Mutating Inputs");

let db = salsa::DatabaseImpl::default();

group.bench_function(BenchmarkId::new("new", "InternedInput"), |b| {
b.iter(|| {
let input: InternedInput = InternedInput::new(&db, "hello, world!".to_owned());
interned_length(&db, input);
})
});

let db = salsa::DatabaseImpl::default();
group.bench_function(BenchmarkId::new("amortized", "InternedInput"), |b| {
let input = InternedInput::new(&db, "hello, world!".to_owned());
let _ = interned_length(&db, input);

b.iter(|| interned_length(&db, input));
});

let db = salsa::DatabaseImpl::default();
group.bench_function(BenchmarkId::new("new", "Input"), |b| {
b.iter(|| {
let input = Input::new(&db, "hello, world!".to_owned());
length(&db, input);
})
});

let db = salsa::DatabaseImpl::default();
group.bench_function(BenchmarkId::new("amortized", "Input"), |b| {
let input = Input::new(&db, "hello, world!".to_owned());
let _ = length(&db, input);
Expand Down

0 comments on commit 418e6ea

Please sign in to comment.