Debian Codegraph @

debian/missing-sources/unicode-normalization/benches/bench.rs

raw
1 #![feature(test)]
2
3 extern crate test;
4 extern crate unicode_normalization;
5
6 use std::fs;
7 use test::Bencher;
8 use unicode_normalization::UnicodeNormalization;
9
10 const ASCII: &str = "all types of normalized";
11 const NFC: &str = "Introducci\u{00f3}n a Unicode.pdf";
12 const NFD: &str = "Introduccio\u{0301}n a Unicode.pdf";
13
14 #[bench]
15 fn bench_is_nfc_ascii(b: &mut Bencher) {
16 b.iter(|| unicode_normalization::is_nfc(ASCII));
17 }
18
19 #[bench]
20 fn bench_is_nfc_normalized(b: &mut Bencher) {
21 b.iter(|| unicode_normalization::is_nfc(NFC));
22 }
23
24 #[bench]
25 fn bench_is_nfc_not_normalized(b: &mut Bencher) {
26 b.iter(|| unicode_normalization::is_nfc(NFD));
27 }
28
29 #[bench]
30 fn bench_is_nfd_ascii(b: &mut Bencher) {
31 b.iter(|| unicode_normalization::is_nfd(ASCII));
32 }
33
34 #[bench]
35 fn bench_is_nfd_normalized(b: &mut Bencher) {
36 b.iter(|| unicode_normalization::is_nfd(NFD));
37 }
38
39 #[bench]
40 fn bench_is_nfd_not_normalized(b: &mut Bencher) {
41 b.iter(|| unicode_normalization::is_nfd(NFC));
42 }
43
44 #[bench]
45 fn bench_is_nfc_stream_safe_ascii(b: &mut Bencher) {
46 b.iter(|| unicode_normalization::is_nfc_stream_safe(ASCII));
47 }
48
49 #[bench]
50 fn bench_is_nfc_stream_safe_normalized(b: &mut Bencher) {
51 b.iter(|| unicode_normalization::is_nfc_stream_safe(NFC));
52 }
53
54 #[bench]
55 fn bench_is_nfc_stream_safe_not_normalized(b: &mut Bencher) {
56 b.iter(|| unicode_normalization::is_nfc_stream_safe(NFD));
57 }
58
59 #[bench]
60 fn bench_is_nfd_stream_safe_ascii(b: &mut Bencher) {
61 b.iter(|| unicode_normalization::is_nfd_stream_safe(ASCII));
62 }
63
64 #[bench]
65 fn bench_is_nfd_stream_safe_normalized(b: &mut Bencher) {
66 b.iter(|| unicode_normalization::is_nfd_stream_safe(NFD));
67 }
68
69 #[bench]
70 fn bench_is_nfd_stream_safe_not_normalized(b: &mut Bencher) {
71 b.iter(|| unicode_normalization::is_nfd_stream_safe(NFC));
72 }
73
74 #[bench]
75 fn bench_nfc_ascii(b: &mut Bencher) {
76 b.iter(|| ASCII.nfc().count());
77 }
78
79 #[bench]
80 fn bench_nfd_ascii(b: &mut Bencher) {
81 b.iter(|| ASCII.nfd().count());
82 }
83
84 #[bench]
85 fn bench_nfc_long(b: &mut Bencher) {
86 let long = fs::read_to_string("benches/long.txt").unwrap();
87 b.iter(|| long.nfc().count());
88 }
89
90 #[bench]
91 fn bench_nfd_long(b: &mut Bencher) {
92 let long = fs::read_to_string("benches/long.txt").unwrap();
93 b.iter(|| long.nfd().count());
94 }
95
96 #[bench]
97 fn bench_nfkc_ascii(b: &mut Bencher) {
98 b.iter(|| ASCII.nfkc().count());
99 }
100
101 #[bench]
102 fn bench_nfkd_ascii(b: &mut Bencher) {
103 b.iter(|| ASCII.nfkd().count());
104 }
105
106 #[bench]
107 fn bench_nfkc_long(b: &mut Bencher) {
108 let long = fs::read_to_string("benches/long.txt").unwrap();
109 b.iter(|| long.nfkc().count());
110 }
111
112 #[bench]
113 fn bench_nfkd_long(b: &mut Bencher) {
114 let long = fs::read_to_string("benches/long.txt").unwrap();
115 b.iter(|| long.nfkd().count());
116 }
117
118 #[bench]
119 fn bench_streamsafe_ascii(b: &mut Bencher) {
120 b.iter(|| ASCII.stream_safe().count());
121 }
122
123 #[bench]
124 fn bench_streamsafe_adversarial(b: &mut Bencher) {
125 let s = "bo\u{0300}\u{0301}\u{0302}\u{0303}\u{0304}\u{0305}\u{0306}\u{0307}\u{0308}\u{0309}\u{030a}\u{030b}\u{030c}\u{030d}\u{030e}\u{030f}\u{0310}\u{0311}\u{0312}\u{0313}\u{0314}\u{0315}\u{0316}\u{0317}\u{0318}\u{0319}\u{031a}\u{031b}\u{031c}\u{031d}\u{032e}oom";
126 b.iter(|| s.stream_safe().count());
127 }