|
| 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 | +#[bench] |
| 10 | +fn bench_is_nfc_ascii(b: &mut Bencher) { |
| 11 | + b.iter(|| unicode_normalization::is_nfc("all types of normalized")); |
| 12 | +} |
| 13 | + |
| 14 | +#[bench] |
| 15 | +fn bench_is_nfc_normalized(b: &mut Bencher) { |
| 16 | + b.iter(|| unicode_normalization::is_nfc("Introducci\u{00f3}n a Unicode.pdf")); |
| 17 | +} |
| 18 | + |
| 19 | +#[bench] |
| 20 | +fn bench_is_nfc_not_normalized(b: &mut Bencher) { |
| 21 | + b.iter(|| unicode_normalization::is_nfc("Introduccio\u{0301}n a Unicode.pdf")); |
| 22 | +} |
| 23 | + |
| 24 | +#[bench] |
| 25 | +fn bench_is_nfd_ascii(b: &mut Bencher) { |
| 26 | + b.iter(|| unicode_normalization::is_nfd("an easy string to check")); |
| 27 | +} |
| 28 | + |
| 29 | +#[bench] |
| 30 | +fn bench_is_nfd_normalized(b: &mut Bencher) { |
| 31 | + b.iter(|| unicode_normalization::is_nfd("Introduccio\u{0301}n a Unicode.pdf")); |
| 32 | +} |
| 33 | + |
| 34 | +#[bench] |
| 35 | +fn bench_is_nfd_not_normalized(b: &mut Bencher) { |
| 36 | + b.iter(|| unicode_normalization::is_nfd("Introducci\u{00f3}n a Unicode.pdf")); |
| 37 | +} |
| 38 | + |
| 39 | +#[bench] |
| 40 | +fn bench_nfc_ascii(b: &mut Bencher) { |
| 41 | + let s = "normalize me please"; |
| 42 | + b.iter(|| s.nfc().count()); |
| 43 | +} |
| 44 | + |
| 45 | +#[bench] |
| 46 | +fn bench_nfd_ascii(b: &mut Bencher) { |
| 47 | + let s = "decompose me entirely"; |
| 48 | + b.iter(|| s.nfd().count()); |
| 49 | +} |
| 50 | + |
| 51 | +#[bench] |
| 52 | +fn bench_streamsafe_ascii(b: &mut Bencher) { |
| 53 | + let s = "quite nonthreatening"; |
| 54 | + b.iter(|| s.stream_safe().count()); |
| 55 | +} |
| 56 | + |
| 57 | +#[bench] |
| 58 | +fn bench_streamsafe_adversarial(b: &mut Bencher) { |
| 59 | + 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"; |
| 60 | + b.iter(|| s.stream_safe().count()); |
| 61 | +} |
0 commit comments