forked from besok/jsonpath-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add rgex bench * fix inter * init impl * add config * fix complains --------- Co-authored-by: Boris Zhguchev <boris.zhguchev@gropyus.com>
- Loading branch information
Showing
11 changed files
with
405 additions
and
86 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
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,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); |
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,16 @@ | ||
pub mod cache; | ||
|
||
use crate::path::config::cache::RegexCache; | ||
|
||
/// Configuration to adjust the jsonpath search | ||
#[derive(Clone, Default)] | ||
pub struct JsonPathConfig { | ||
/// cache to provide | ||
pub regex_cache: RegexCache, | ||
} | ||
|
||
impl JsonPathConfig { | ||
pub fn new(regex_cache: RegexCache) -> Self { | ||
Self { regex_cache } | ||
} | ||
} |
Oops, something went wrong.