-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #542 from nikomatsakis/codspeed
Merge Codspeed
- Loading branch information
Showing
3 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
use codspeed_criterion_compat::{criterion_group, criterion_main, BatchSize, Criterion}; | ||
use salsa::Setter; | ||
|
||
#[salsa::input] | ||
struct Input { | ||
field: usize, | ||
} | ||
|
||
#[salsa::tracked] | ||
struct Tracked<'db> { | ||
number: usize, | ||
} | ||
|
||
#[salsa::tracked(return_ref)] | ||
fn index<'db>(db: &'db dyn salsa::Database, input: Input) -> Vec<Tracked<'db>> { | ||
(0..input.field(db)).map(|i| Tracked::new(db, i)).collect() | ||
} | ||
|
||
#[salsa::tracked] | ||
fn root(db: &dyn salsa::Database, input: Input) -> usize { | ||
let index = index(db, input); | ||
index.len() | ||
} | ||
|
||
fn many_tracked_structs(criterion: &mut Criterion) { | ||
criterion.bench_function("many_tracked_structs", |b| { | ||
b.iter_batched_ref( | ||
|| { | ||
let db = salsa::default_database(); | ||
|
||
let input = Input::new(&db, 1_000); | ||
let input2 = Input::new(&db, 1); | ||
|
||
// prewarm cache | ||
let _ = root(&db, input); | ||
let _ = root(&db, input2); | ||
|
||
(db, input, input2) | ||
}, | ||
|(db, input, input2)| { | ||
// Make a change, but fetch the result for the other input | ||
input2.set_field(db).to(2); | ||
|
||
let result = root(db, *input); | ||
|
||
assert_eq!(result, 1_000); | ||
}, | ||
BatchSize::LargeInput, | ||
); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, many_tracked_structs); | ||
criterion_main!(benches); |