-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use criterion::{black_box, criterion_group, criterion_main, Criterion}; | ||
use jsonpath_rust::{JsonPathInst, JsonPathQuery}; | ||
use serde_json::json; | ||
use std::str::FromStr; | ||
|
||
struct SearchData { | ||
json: serde_json::Value, | ||
path: JsonPathInst, | ||
} | ||
|
||
const PATH: &'static str = "$.[?(@.author ~= '.*(?i)d\\(Rees\\)')]"; | ||
|
||
fn path_with_cache(cfg: &SearchData) { | ||
let _v = jsonpath_rust::find(&cfg.path, &cfg.json); | ||
} | ||
|
||
fn path_without_cache() { | ||
let json = Box::new(json!({ | ||
"author":"abcd(Rees)", | ||
})); | ||
|
||
let _v = json.path(PATH).expect("the path is correct"); | ||
} | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
let data = SearchData { | ||
json: json!({ | ||
"author":"abcd(Rees)", | ||
}), | ||
path: JsonPathInst::from_str("$..book[?(@.author size 10)].title").unwrap(), | ||
}; | ||
c.bench_function("regex bench without cache", |b| { | ||
b.iter(|| path_without_cache()) | ||
}); | ||
c.bench_function("regex bench with cache", |b| { | ||
b.iter(|| path_with_cache(&data)) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |