forked from besok/jsonpath-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregex_bench.rs
40 lines (34 loc) · 1.25 KB
/
regex_bench.rs
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
use criterion::{black_box, criterion_group, criterion_main, Criterion};
use jsonpath_rust::path::config::cache::{DefaultRegexCacheInst, RegexCache};
use jsonpath_rust::path::config::JsonPathConfig;
use jsonpath_rust::{JsonPathFinder, JsonPathInst, JsonPathQuery};
use once_cell::sync::Lazy;
use serde_json::{json, Value};
use std::str::FromStr;
fn regex_perf_test_with_cache(cfg: JsonPathConfig) {
let json = Box::new(json!({
"author":"abcd(Rees)",
}));
let _v = (json, cfg)
.path("$.[?(@.author ~= '.*(?i)d\\(Rees\\)')]")
.expect("the path is correct");
}
fn regex_perf_test_without_cache() {
let json = Box::new(json!({
"author":"abcd(Rees)",
}));
let _v = json
.path("$.[?(@.author ~= '.*(?i)d\\(Rees\\)')]")
.expect("the path is correct");
}
pub fn criterion_benchmark(c: &mut Criterion) {
let cfg = JsonPathConfig::new(RegexCache::Implemented(DefaultRegexCacheInst::default()));
c.bench_function("regex bench without cache", |b| {
b.iter(|| regex_perf_test_without_cache())
});
c.bench_function("regex bench with cache", |b| {
b.iter(|| regex_perf_test_with_cache(cfg.clone()))
});
}
criterion_group!(benches, criterion_benchmark);
criterion_main!(benches);