Mercurial > lbo > hg > rex
changeset 59:46bbd73f7dcb
Extend benchmarks
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Fri, 30 Aug 2019 16:30:41 +0200 |
parents | 7532e9000d89 |
children | 197ee4af43af |
files | Cargo.toml README.md benches/e2e.rs |
diffstat | 3 files changed, 29 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/Cargo.toml Fri Aug 30 15:55:38 2019 +0200 +++ b/Cargo.toml Fri Aug 30 16:30:41 2019 +0200 @@ -7,6 +7,7 @@ [dev-dependencies] bencher = "0.1" +regex = "1.2" [[bench]] name = "e2e"
--- a/README.md Fri Aug 30 15:55:38 2019 +0200 +++ b/README.md Fri Aug 30 16:30:41 2019 +0200 @@ -1,6 +1,9 @@ # rex -rex is a mere playground where I'm trying to write an engine for parsing, compiling and matching regular expressions. +rex is a mere playground where I'm trying to write an engine for parsing, +compiling and matching regular expressions. + +It's a bit slow right now. Consider the code licensed under the MIT license.
--- a/benches/e2e.rs Fri Aug 30 15:55:38 2019 +0200 +++ b/benches/e2e.rs Fri Aug 30 16:30:41 2019 +0200 @@ -1,14 +1,36 @@ #[macro_use] extern crate bencher; +extern crate regex; use bencher::Bencher; fn bench_simple_re(b: &mut Bencher) { b.iter(|| { - assert!(rex::match_re_str("(Hello)? [Ww]orld!?", "Hello world").unwrap().0); + assert!(rex::match_re_str("^(Hello)? [Ww]orld!?$", "Hello world").unwrap().0); + }); +} + +fn bench_simple_precompile(b: &mut Bencher) { + let re = rex::compile("^(Hello)? [Ww]orld!?$").unwrap(); + b.iter(|| { + assert!(rex::match_re(&re, "Hello world").0); }); } -benchmark_group!(benchs, bench_simple_re); +fn bench_notorious(b: &mut Bencher) { + let re = rex::compile("(x+x+)+y").unwrap(); + b.iter(|| { + assert!(rex::match_re(&re, "xxxxxxxxxxxy").0); + }); +} + +fn bench_regex_crate(b: &mut Bencher) { + let re = regex::Regex::new("^(Hello)? [Ww]orld!?$").unwrap(); + b.iter(|| { + assert!(re.is_match("Hello World")); + }); +} + +benchmark_group!(benchs, bench_simple_re, bench_simple_precompile, bench_notorious, bench_regex_crate); benchmark_main!(benchs);