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 <[email protected]>
- 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "jsonpath-rust" | ||
description = "The library provides the basic functionality to find the set of the data according to the filtering query." | ||
version = "0.4.0" | ||
version = "0.5.0" | ||
authors = ["BorisZhguchev <[email protected]>"] | ||
edition = "2018" | ||
license-file = "LICENSE" | ||
|
@@ -17,6 +17,12 @@ regex = "1" | |
pest = "2.0" | ||
pest_derive = "2.0" | ||
thiserror = "1.0.50" | ||
lazy_static = "1.4" | ||
once_cell = "1.19.0" | ||
|
||
[dev-dependencies] | ||
lazy_static = "1.0" | ||
criterion = "0.5.1" | ||
|
||
[[bench]] | ||
name = "regex_bench" | ||
harness = false |
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.