-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed wildcard and string matching benchmarks
- Loading branch information
Showing
6 changed files
with
273 additions
and
81 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,50 @@ | ||
// std imports | ||
use std::alloc::System; | ||
|
||
// third-party imports | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use stats_alloc::{StatsAlloc, INSTRUMENTED_SYSTEM}; | ||
use std::hint::black_box; | ||
|
||
#[global_allocator] | ||
static GLOBAL: &StatsAlloc<System> = &INSTRUMENTED_SYSTEM; | ||
|
||
fn benchmark(c: &mut Criterion) { | ||
let mut c = c.benchmark_group("string"); | ||
let prefix = String::from("_"); | ||
|
||
c.bench_function("string-short-match", |b| { | ||
let what = String::from("_TEST"); | ||
b.iter(|| { | ||
assert_eq!(black_box(&what).starts_with(black_box(&prefix)), true); | ||
}); | ||
}); | ||
c.bench_function("string-long-match", |b| { | ||
let what = String::from("_TEST_SOME_VERY_VERY_LONG_NAME"); | ||
b.iter(|| { | ||
assert_eq!(black_box(&what).starts_with(black_box(&prefix)), true); | ||
}); | ||
}); | ||
c.bench_function("string-short-non-match", |b| { | ||
let what = String::from("TEST"); | ||
b.iter(|| { | ||
assert_eq!(black_box(&what).starts_with(black_box(&prefix)), false); | ||
}); | ||
}); | ||
c.bench_function("string-long-non-match", |b| { | ||
let what = String::from("TEST_SOME_VERY_VERY_LONG_NAME"); | ||
b.iter(|| { | ||
assert_eq!(black_box(&what).starts_with(black_box(&prefix)), false); | ||
}); | ||
}); | ||
c.bench_function("string-long-prefix-match", |b| { | ||
let prefix = String::from("TEST_SOME_VERY_VERY_LONG_PREFIX_"); | ||
let what = String::from("TEST_SOME_VERY_VERY_LONG_PREFIX_AND_SOMEWHAT"); | ||
b.iter(|| { | ||
assert_eq!(black_box(&what).starts_with(black_box(&prefix)), true); | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, benchmark); | ||
criterion_main!(benches); |
This file was deleted.
Oops, something went wrong.
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,72 @@ | ||
// std imports | ||
use std::alloc::System; | ||
|
||
// third-party imports | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use stats_alloc::{Region, StatsAlloc, INSTRUMENTED_SYSTEM}; | ||
use std::hint::black_box; | ||
use wildflower::Pattern; | ||
|
||
#[global_allocator] | ||
static GLOBAL: &StatsAlloc<System> = &INSTRUMENTED_SYSTEM; | ||
|
||
fn benchmark(c: &mut Criterion) { | ||
let mut c = c.benchmark_group("wildflower"); | ||
let pattern = Pattern::new(r"_*"); | ||
|
||
let mut c1 = None; | ||
let mut n1 = 0; | ||
c.bench_function("wildflower-short-match", |b| { | ||
let what = "_TEST"; | ||
let reg = Region::new(&GLOBAL); | ||
b.iter(|| { | ||
assert_eq!(black_box(&pattern).matches(black_box(&what)), true); | ||
n1 += 1; | ||
}); | ||
c1 = Some(reg.change()); | ||
}); | ||
println!("allocations at 1 ({:?} iterations): {:#?}", n1, c1); | ||
|
||
let mut c2 = None; | ||
let mut n2 = 0; | ||
c.bench_function("wildflower-long-match", |b| { | ||
let what = "_TEST_SOME_VERY_VERY_LONG_NAME"; | ||
let reg = Region::new(&GLOBAL); | ||
b.iter(|| { | ||
assert_eq!(black_box(&pattern).matches(black_box(&what)), true); | ||
n2 += 1; | ||
}); | ||
c2 = Some(reg.change()); | ||
}); | ||
println!("allocations at 2 ({:?} iterations): {:#?}", n2, c2); | ||
|
||
let mut c2 = None; | ||
let mut n2 = 0; | ||
c.bench_function("wildflower-long-prefix-match", |b| { | ||
let pattern = Pattern::new(r"SOME_VERY_VERY_LONG_PREFIX_*"); | ||
let what = "SOME_VERY_VERY_LONG_PREFIX_AND_SOMEWHAT"; | ||
let reg = Region::new(&GLOBAL); | ||
b.iter(|| { | ||
assert_eq!(black_box(&pattern).matches(black_box(&what)), true); | ||
n2 += 1; | ||
}); | ||
c2 = Some(reg.change()); | ||
}); | ||
println!("allocations at 2 ({:?} iterations): {:#?}", n2, c2); | ||
|
||
c.bench_function("wildflower-short-non-match", |b| { | ||
let what = "TEST"; | ||
b.iter(|| { | ||
assert_eq!(black_box(&pattern).matches(black_box(&what)), false); | ||
}); | ||
}); | ||
c.bench_function("wildflower-long-non-match", |b| { | ||
let what = "TEST_SOME_VERY_VERY_LONG_NAME"; | ||
b.iter(|| { | ||
assert_eq!(black_box(&pattern).matches(black_box(&what)), false); | ||
}); | ||
}); | ||
} | ||
|
||
criterion_group!(benches, benchmark); | ||
criterion_main!(benches); |
Oops, something went wrong.