1
0
mirror of https://github.com/fluencelabs/jsonpath synced 2025-03-30 21:51:02 +00:00

53 lines
1.5 KiB
Rust
Raw Normal View History

2019-02-19 08:20:59 +09:00
#![feature(test)]
2019-03-07 18:44:06 +09:00
extern crate jsonpath_lib as jsonpath;
2019-02-19 08:20:59 +09:00
extern crate serde_json;
extern crate test;
use std::io::Read;
use serde_json::Value;
use self::test::Bencher;
fn read_json(path: &str) -> String {
let mut f = std::fs::File::open(path).unwrap();
let mut contents = String::new();
f.read_to_string(&mut contents).unwrap();
contents
}
#[bench]
2019-03-14 22:30:42 +09:00
fn bench_selector(b: &mut Bencher) {
2019-03-07 18:44:06 +09:00
let string = read_json("./benches/example.json");
2019-03-14 22:30:42 +09:00
let path = r#"$..book[?(@.price<30 && @.category=="fiction")]"#;
2019-03-07 18:44:06 +09:00
let json: Value = serde_json::from_str(string.as_str()).unwrap();
2019-03-14 22:30:42 +09:00
let mut selector = jsonpath::selector(&json);
2019-02-19 08:20:59 +09:00
b.iter(move || {
2019-03-14 22:30:42 +09:00
for _ in 1..1000 {
let _ = selector(path).unwrap();
}
});
}
#[bench]
fn bench_select(b: &mut Bencher) {
let string = read_json("./benches/example.json");
let path = r#"$..book[?(@.price<30 && @.category=="fiction")]"#;
let json: Value = serde_json::from_str(string.as_str()).unwrap();
b.iter(move || {
for _ in 1..1000 {
let _ = jsonpath::select(&json, path).unwrap();
}
});
}
#[bench]
fn bench_compile(b: &mut Bencher) {
let string = read_json("./benches/example.json");
let path = r#"$..book[?(@.price<30 && @.category=="fiction")]"#;
let json: Value = serde_json::from_str(string.as_str()).unwrap();
let mut template = jsonpath::compile(path);
b.iter(move || {
for _ in 1..1000 {
let _ = template(&json).unwrap();
2019-02-19 08:20:59 +09:00
}
});
}