Skip to content

Commit

Permalink
bench: Deref the LazyLock outside the benchmarked loop
Browse files Browse the repository at this point in the history
Otherwise we're also benchmarking the test data init.
  • Loading branch information
vincentdephily committed Jan 31, 2025
1 parent f2146e6 commit 03b6810
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/parse/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,10 @@ mod bench {
/// Bench creating a filter and applying it on many strings
fn $n(b: &mut test::Bencher) {
let t: Vec<String> = $t.split_whitespace().map(str::to_string).collect();
let pkgs = &*PKGS;
b.iter(move || {
let f = FilterStr::try_new(&t, $e).unwrap();
PKGS.iter().fold(true, |a, p| a ^ f.match_pkg(&p))
pkgs.iter().fold(true, |a, p| a ^ f.match_pkg(&p))
});
}
};
Expand All @@ -713,8 +714,9 @@ mod bench {

#[bench]
fn parse_version_(b: &mut test::Bencher) {
let pkgs = &*PKGS;
b.iter(move || {
for p in &*PKGS {
for p in pkgs {
parse_version(&p, &FilterStr::True);
}
});
Expand Down Expand Up @@ -769,9 +771,10 @@ mod bench {
#[bench]
fn $n(b: &mut test::Bencher) {
let filter = FilterStr::try_new(&vec![], true).unwrap();
let lines = &*EMERGE_LINES;
b.iter(move || {
let mut found = 0;
for (l1, l2) in &*EMERGE_LINES {
for (l1, l2) in lines {
found += $f(&filter, l1, l2).is_some() as u32;
}
assert!(found > 2, "Only {found} matches for {}", stringify!($f));
Expand Down

0 comments on commit 03b6810

Please sign in to comment.