File: bench.rs

package info (click to toggle)
rust-unicode-normalization 0.1.7-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,304 kB
  • sloc: python: 295; makefile: 2
file content (92 lines) | stat: -rw-r--r-- 2,456 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#![feature(test)]
#![feature(iterator_step_by)]
extern crate unicode_normalization;
extern crate test;

use test::Bencher;
use unicode_normalization::UnicodeNormalization;

const ASCII: &'static str = "all types of normalized";
const NFC: &'static str = "Introducci\u{00f3}n a Unicode.pdf";
const NFD: &'static str = "Introduccio\u{0301}n a Unicode.pdf";

#[bench]
fn bench_is_nfc_ascii(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfc(ASCII));
}

#[bench]
fn bench_is_nfc_normalized(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfc(NFC));
}

#[bench]
fn bench_is_nfc_not_normalized(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfc(NFD));
}

#[bench]
fn bench_is_nfd_ascii(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfd(ASCII));
}

#[bench]
fn bench_is_nfd_normalized(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfd(NFD));
}

#[bench]
fn bench_is_nfd_not_normalized(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfd(NFC));
}

#[bench]
fn bench_is_nfc_stream_safe_ascii(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfc_stream_safe(ASCII));
}

#[bench]
fn bench_is_nfc_stream_safe_normalized(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfc_stream_safe(NFC));
}

#[bench]
fn bench_is_nfc_stream_safe_not_normalized(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfc_stream_safe(NFD));
}

#[bench]
fn bench_is_nfd_stream_safe_ascii(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfd_stream_safe(ASCII));
}

#[bench]
fn bench_is_nfd_stream_safe_normalized(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfd_stream_safe(NFD));
}

#[bench]
fn bench_is_nfd_stream_safe_not_normalized(b: &mut Bencher) {
    b.iter(|| unicode_normalization::is_nfd_stream_safe(NFC));
}

#[bench]
fn bench_nfc_ascii(b: &mut Bencher) {
    b.iter(|| ASCII.nfc().count());
}

#[bench]
fn bench_nfd_ascii(b: &mut Bencher) {
    b.iter(|| ASCII.nfd().count());
}

#[bench]
fn bench_streamsafe_ascii(b: &mut Bencher) {
    b.iter(|| ASCII.stream_safe().count());
}

#[bench]
fn bench_streamsafe_adversarial(b: &mut Bencher) {
    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";
    b.iter(|| s.stream_safe().count());
}