File: bench.rs

package info (click to toggle)
rustc 1.34.2%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 190,620 kB
  • sloc: xml: 133,832; ansic: 22,822; sh: 14,012; asm: 7,935; python: 5,292; cpp: 4,715; awk: 3,426; makefile: 2,601; yacc: 1,618; lex: 350; ruby: 68; pascal: 46
file content (73 lines) | stat: -rw-r--r-- 1,716 bytes parent folder | download | duplicates (14)
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
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(test)]

extern crate regex_syntax;
extern crate test;

use regex_syntax::Parser;
use test::Bencher;

#[bench]
fn parse_simple1(b: &mut Bencher) {
    b.iter(|| {
        let re = r"^bc(d|e)*$";
        Parser::new().parse(re).unwrap()
    });
}

#[bench]
fn parse_simple2(b: &mut Bencher) {
    b.iter(|| {
        let re = r"'[a-zA-Z_][a-zA-Z0-9_]*(')\b";
        Parser::new().parse(re).unwrap()
    });
}

#[bench]
fn parse_small1(b: &mut Bencher) {
    b.iter(|| {
        let re = r"\p{L}|\p{N}|\s|.|\d";
        Parser::new().parse(re).unwrap()
    });
}

#[bench]
fn parse_medium1(b: &mut Bencher) {
    b.iter(|| {
        let re = r"\pL\p{Greek}\p{Hiragana}\p{Alphabetic}\p{Hebrew}\p{Arabic}";
        Parser::new().parse(re).unwrap()
    });
}

#[bench]
fn parse_medium2(b: &mut Bencher) {
    b.iter(|| {
        let re = r"\s\S\w\W\d\D";
        Parser::new().parse(re).unwrap()
    });
}

#[bench]
fn parse_medium3(b: &mut Bencher) {
    b.iter(|| {
        let re = r"\p{age:3.2}\p{hira}\p{scx:hira}\p{alphabetic}\p{sc:Greek}\pL";
        Parser::new().parse(re).unwrap()
    });
}

#[bench]
fn parse_huge(b: &mut Bencher) {
    b.iter(|| {
        let re = r"\p{L}{100}";
        Parser::new().parse(re).unwrap()
    });
}