-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use tr::tr; | ||
|
||
pub fn short_literal(c: &mut Criterion) { | ||
c.bench_function("short_literal", |b| b.iter(|| { | ||
tr!("Hello"); | ||
})); | ||
} | ||
|
||
pub fn long_literal(c: &mut Criterion) { | ||
c.bench_function("long_literal", |b| b.iter(|| { | ||
tr!("Hello, world! This is a longer sentence but without argument markers. That is all for now, thank you for reading."); | ||
})); | ||
} | ||
|
||
pub fn short_argument(c: &mut Criterion) { | ||
c.bench_function("short_argument", |b| b.iter(|| { | ||
tr!("Hello {}!", black_box("world")); | ||
})); | ||
} | ||
|
||
pub fn long_argument(c: &mut Criterion) { | ||
c.bench_function("long_argument", |b| b.iter(|| { | ||
tr!("Hello {} and {} and {} and {} and {} and {} and {} and finally {}!", | ||
black_box("Mercury"), | ||
black_box("Venus"), | ||
black_box("Earth"), | ||
black_box("Mars"), | ||
black_box("Jupiter"), | ||
black_box("Saturn"), | ||
black_box("Uranus"), | ||
black_box("Neptune"), | ||
); | ||
})); | ||
} | ||
|
||
criterion_group!(benches, short_literal, long_literal, short_argument, long_argument); | ||
criterion_main!(benches); |