Skip to content

Commit 95b99a8

Browse files
committed
add benches for find slicing
regex bench without cache time: [85.023 µs 85.199 µs 85.434 µs] Found 18 outliers among 100 measurements (18.00%) 4 (4.00%) high mild 14 (14.00%) high severe regex bench with cache time: [550.84 ns 551.27 ns 551.69 ns] Found 2 outliers among 100 measurements (2.00%) 2 (2.00%) high severe
1 parent 994a3ec commit 95b99a8

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ thiserror = "1.0.50"
2020

2121
[dev-dependencies]
2222
lazy_static = "1.0"
23+
criterion = "0.5.1"
24+
25+
[[bench]]
26+
name = "regex_bench"
27+
harness = false

benches/regex_bench.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
use jsonpath_rust::{JsonPathInst, JsonPathQuery};
3+
use serde_json::json;
4+
use std::str::FromStr;
5+
6+
struct SearchData {
7+
json: serde_json::Value,
8+
path: JsonPathInst,
9+
}
10+
11+
const PATH: &'static str = "$.[?(@.author ~= '.*(?i)d\\(Rees\\)')]";
12+
13+
fn path_with_cache(cfg: &SearchData) {
14+
let _v = jsonpath_rust::find(&cfg.path, &cfg.json);
15+
}
16+
17+
fn path_without_cache() {
18+
let json = Box::new(json!({
19+
"author":"abcd(Rees)",
20+
}));
21+
22+
let _v = json.path(PATH).expect("the path is correct");
23+
}
24+
25+
pub fn criterion_benchmark(c: &mut Criterion) {
26+
let data = SearchData {
27+
json: json!({
28+
"author":"abcd(Rees)",
29+
}),
30+
path: JsonPathInst::from_str("$..book[?(@.author size 10)].title").unwrap(),
31+
};
32+
c.bench_function("regex bench without cache", |b| {
33+
b.iter(|| path_without_cache())
34+
});
35+
c.bench_function("regex bench with cache", |b| {
36+
b.iter(|| path_with_cache(&data))
37+
});
38+
}
39+
40+
criterion_group!(benches, criterion_benchmark);
41+
criterion_main!(benches);

0 commit comments

Comments
 (0)