Skip to content

Commit e97357d

Browse files
committed
Add benchmarks
1 parent 97ebf36 commit e97357d

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

benches/bench.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#![feature(test)]
2+
#![feature(iterator_step_by)]
3+
extern crate unicode_normalization;
4+
extern crate test;
5+
6+
use test::Bencher;
7+
use unicode_normalization::UnicodeNormalization;
8+
9+
macro_rules! bench_check {
10+
($b: ident, $s: expr, $form: ident) => {
11+
let s = $s;
12+
$b.iter(|| s.chars().eq(s.$form()));
13+
}
14+
}
15+
16+
#[bench]
17+
fn bench_is_nfc_ascii(b: &mut Bencher) {
18+
bench_check!(b, "all types of normalized", nfc);
19+
}
20+
21+
#[bench]
22+
fn bench_is_nfc_normalized(b: &mut Bencher) {
23+
bench_check!(b, "Introducci\u{00f3}n a Unicode.pdf", nfc);
24+
}
25+
26+
#[bench]
27+
fn bench_is_nfc_not_normalized(b: &mut Bencher) {
28+
bench_check!(b, "Introduccio\u{0301}n a Unicode.pdf", nfc);
29+
}
30+
31+
#[bench]
32+
fn bench_is_nfd_ascii(b: &mut Bencher) {
33+
bench_check!(b, "an easy string to check", nfd);
34+
}
35+
36+
#[bench]
37+
fn bench_is_nfd_normalized(b: &mut Bencher) {
38+
bench_check!(b, "Introduccio\u{0301}n a Unicode.pdf", nfd);
39+
}
40+
41+
#[bench]
42+
fn bench_is_nfd_not_normalized(b: &mut Bencher) {
43+
bench_check!(b, "Introducci\u{00f3}n a Unicode.pdf", nfd);
44+
}
45+
46+
#[bench]
47+
fn bench_nfc_ascii(b: &mut Bencher) {
48+
let s = "normalize me please";
49+
b.iter(|| s.nfc().count());
50+
}
51+
52+
#[bench]
53+
fn bench_nfd_ascii(b: &mut Bencher) {
54+
let s = "decompose me entirely";
55+
b.iter(|| s.nfd().count());
56+
}

0 commit comments

Comments
 (0)