Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit243af2c

Browse files
authored
Merge pull request#113 from indutny/fix/benchmarks
use criterion.rs for word benchmarks
2 parents07e6155 +b59b1ce commit243af2c

File tree

2 files changed

+52
-58
lines changed

2 files changed

+52
-58
lines changed

‎benches/unicode_words.rs‎

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,52 @@
1-
#[macro_use]
2-
externcrate bencher;
3-
externcrate unicode_segmentation;
1+
use criterion::{black_box, criterion_group, criterion_main,Criterion};
42

5-
use bencher::Bencher;
63
use std::fs;
74
use unicode_segmentation::UnicodeSegmentation;
85

9-
fnunicode_words(bench:&mutBencher,path:&str){
6+
fnunicode_words(c:&mutCriterion,lang:&str,path:&str){
107
let text = fs::read_to_string(path).unwrap();
11-
bench.iter(||{
12-
for win text.unicode_words(){
13-
bencher::black_box(w);
14-
}
8+
c.bench_function(&format!("unicode_words_{}", lang), |bench|{
9+
bench.iter(||{
10+
for win text.unicode_words(){
11+
black_box(w);
12+
}
13+
})
1514
});
16-
17-
bench.bytes = text.len()asu64;
1815
}
1916

20-
fnunicode_words_arabic(bench:&mutBencher){
21-
unicode_words(bench,"benches/texts/arabic.txt");
17+
fnunicode_words_arabic(c:&mutCriterion){
18+
unicode_words(c,"arabic","benches/texts/arabic.txt");
2219
}
2320

24-
fnunicode_words_english(bench:&mutBencher){
25-
unicode_words(bench,"benches/texts/english.txt");
21+
fnunicode_words_english(c:&mutCriterion){
22+
unicode_words(c,"english","benches/texts/english.txt");
2623
}
2724

28-
fnunicode_words_hindi(bench:&mutBencher){
29-
unicode_words(bench,"benches/texts/hindi.txt");
25+
fnunicode_words_hindi(c:&mutCriterion){
26+
unicode_words(c,"hindi","benches/texts/hindi.txt");
3027
}
3128

32-
fnunicode_words_japanese(bench:&mutBencher){
33-
unicode_words(bench,"benches/texts/japanese.txt");
29+
fnunicode_words_japanese(c:&mutCriterion){
30+
unicode_words(c,"japanese","benches/texts/japanese.txt");
3431
}
3532

36-
fnunicode_words_korean(bench:&mutBencher){
37-
unicode_words(bench,"benches/texts/korean.txt");
33+
fnunicode_words_korean(c:&mutCriterion){
34+
unicode_words(c,"korean","benches/texts/korean.txt");
3835
}
3936

40-
fnunicode_words_mandarin(bench:&mutBencher){
41-
unicode_words(bench,"benches/texts/mandarin.txt");
37+
fnunicode_words_mandarin(c:&mutCriterion){
38+
unicode_words(c,"mandarin","benches/texts/mandarin.txt");
4239
}
4340

44-
fnunicode_words_russian(bench:&mutBencher){
45-
unicode_words(bench,"benches/texts/russian.txt");
41+
fnunicode_words_russian(c:&mutCriterion){
42+
unicode_words(c,"russian","benches/texts/russian.txt");
4643
}
4744

48-
fnunicode_words_source_code(bench:&mutBencher){
49-
unicode_words(bench,"benches/texts/source_code.txt");
45+
fnunicode_words_source_code(c:&mutCriterion){
46+
unicode_words(c,"source_code","benches/texts/source_code.txt");
5047
}
5148

52-
benchmark_group!(
49+
criterion_group!(
5350
benches,
5451
unicode_words_arabic,
5552
unicode_words_english,
@@ -61,4 +58,4 @@ benchmark_group!(
6158
unicode_words_source_code,
6259
);
6360

64-
benchmark_main!(benches);
61+
criterion_main!(benches);

‎benches/word_bounds.rs‎

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,52 @@
1-
#[macro_use]
2-
externcrate bencher;
3-
externcrate unicode_segmentation;
1+
use criterion::{black_box, criterion_group, criterion_main,Criterion};
42

5-
use bencher::Bencher;
63
use std::fs;
74
use unicode_segmentation::UnicodeSegmentation;
85

9-
fnword_bounds(bench:&mutBencher,path:&str){
6+
fnword_bounds(c:&mutCriterion,lang:&str,path:&str){
107
let text = fs::read_to_string(path).unwrap();
11-
bench.iter(||{
12-
for win text.split_word_bounds(){
13-
bencher::black_box(w);
14-
}
8+
c.bench_function(&format!("word_bounds_{}", lang), |bench|{
9+
bench.iter(||{
10+
for win text.split_word_bounds(){
11+
black_box(w);
12+
}
13+
});
1514
});
16-
17-
bench.bytes = text.len()asu64;
1815
}
1916

20-
fnword_bounds_arabic(bench:&mutBencher){
21-
word_bounds(bench,"benches/texts/arabic.txt");
17+
fnword_bounds_arabic(c:&mutCriterion){
18+
word_bounds(c,"arabic","benches/texts/arabic.txt");
2219
}
2320

24-
fnword_bounds_english(bench:&mutBencher){
25-
word_bounds(bench,"benches/texts/english.txt");
21+
fnword_bounds_english(c:&mutCriterion){
22+
word_bounds(c,"english","benches/texts/english.txt");
2623
}
2724

28-
fnword_bounds_hindi(bench:&mutBencher){
29-
word_bounds(bench,"benches/texts/hindi.txt");
25+
fnword_bounds_hindi(c:&mutCriterion){
26+
word_bounds(c,"hindi","benches/texts/hindi.txt");
3027
}
3128

32-
fnword_bounds_japanese(bench:&mutBencher){
33-
word_bounds(bench,"benches/texts/japanese.txt");
29+
fnword_bounds_japanese(c:&mutCriterion){
30+
word_bounds(c,"japanese","benches/texts/japanese.txt");
3431
}
3532

36-
fnword_bounds_korean(bench:&mutBencher){
37-
word_bounds(bench,"benches/texts/korean.txt");
33+
fnword_bounds_korean(c:&mutCriterion){
34+
word_bounds(c,"korean","benches/texts/korean.txt");
3835
}
3936

40-
fnword_bounds_mandarin(bench:&mutBencher){
41-
word_bounds(bench,"benches/texts/mandarin.txt");
37+
fnword_bounds_mandarin(c:&mutCriterion){
38+
word_bounds(c,"mandarin","benches/texts/mandarin.txt");
4239
}
4340

44-
fnword_bounds_russian(bench:&mutBencher){
45-
word_bounds(bench,"benches/texts/russian.txt");
41+
fnword_bounds_russian(c:&mutCriterion){
42+
word_bounds(c,"russian","benches/texts/russian.txt");
4643
}
4744

48-
fnword_bounds_source_code(bench:&mutBencher){
49-
word_bounds(bench,"benches/texts/source_code.txt");
45+
fnword_bounds_source_code(c:&mutCriterion){
46+
word_bounds(c,"source_code","benches/texts/source_code.txt");
5047
}
5148

52-
benchmark_group!(
49+
criterion_group!(
5350
benches,
5451
word_bounds_arabic,
5552
word_bounds_english,
@@ -61,4 +58,4 @@ benchmark_group!(
6158
word_bounds_source_code,
6259
);
6360

64-
benchmark_main!(benches);
61+
criterion_main!(benches);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp