-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented more efficient test str and test str any
- Loading branch information
Showing
3 changed files
with
142 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use text_scanner::{Scanner, ScannerItem}; | ||
|
||
fn bench_accept_vs_test(c: &mut Criterion) { | ||
let scanner = Scanner::new("// Hello World"); | ||
|
||
let mut group = c.benchmark_group("str"); | ||
group.bench_function("accept_str", |b| { | ||
b.iter(|| -> ScannerItem<&'_ str> { | ||
let mut scanner = scanner.clone(); | ||
scanner.accept_str("//").unwrap() | ||
}); | ||
}); | ||
group.bench_function("test_str", |b| { | ||
b.iter(|| -> ScannerItem<&'_ str> { | ||
let mut scanner = scanner.clone(); | ||
scanner.test_str("//").unwrap() | ||
}); | ||
}); | ||
group.finish(); | ||
|
||
let mut group = c.benchmark_group("str_any"); | ||
group.bench_function("accept_str_any", |b| { | ||
b.iter(|| -> ScannerItem<&'_ str> { | ||
let mut scanner = scanner.clone(); | ||
scanner | ||
.accept_str_any(&["// foo", "// bar", "// baz", "//"]) | ||
.unwrap() | ||
}); | ||
}); | ||
group.bench_function("test_str_any", |b| { | ||
b.iter(|| -> ScannerItem<&'_ str> { | ||
let mut scanner = scanner.clone(); | ||
scanner | ||
.test_str_any(&["// foo", "// bar", "// baz", "//"]) | ||
.unwrap() | ||
}); | ||
}); | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, bench_accept_vs_test); | ||
criterion_main!(benches); |
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