mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-06-14 00:21:25 +00:00
lua 프로젝트 레이아웃 변경
This commit is contained in:
20
lua/bench_lua_vs_rust/example.lua
Normal file
20
lua/bench_lua_vs_rust/example.lua
Normal file
@ -0,0 +1,20 @@
|
||||
require("lib")
|
||||
|
||||
local iter;
|
||||
if arg[1] == nil or arg[1] == '' then
|
||||
iter = 5000;
|
||||
else
|
||||
iter = tonumber(arg[1]);
|
||||
end
|
||||
|
||||
print(string.format("%s - %u", "lua iter", iter));
|
||||
|
||||
local file = io.open("../benchmark/example.json", "r");
|
||||
io.input(file)
|
||||
local data = io.read("*a");
|
||||
io.close(file);
|
||||
local template = compile("$..book[?(@.price<30 && @.category==\"fiction\")]");
|
||||
for i = 0, iter do
|
||||
local r = template(data);
|
||||
-- print(r);
|
||||
end
|
46
lua/bench_lua_vs_rust/example.rs
Normal file
46
lua/bench_lua_vs_rust/example.rs
Normal file
@ -0,0 +1,46 @@
|
||||
extern crate jsonpath_lib as jsonpath;
|
||||
extern crate serde;
|
||||
extern crate serde_json;
|
||||
|
||||
use std::io::Read;
|
||||
|
||||
use serde_json::Value;
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
fn get_string() -> String {
|
||||
read_json("../benchmark/example.json")
|
||||
}
|
||||
|
||||
fn get_json() -> Value {
|
||||
let string = get_string();
|
||||
serde_json::from_str(string.as_str()).unwrap()
|
||||
}
|
||||
|
||||
fn get_path() -> &'static str {
|
||||
r#"$..book[?(@.price<30 && @.category=="fiction")]"#
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let iter = if args.len() < 2 { 5000_usize } else { args[1].as_str().parse::<usize>().unwrap() };
|
||||
|
||||
println!("rust iter - {}", iter);
|
||||
|
||||
let json = get_json();
|
||||
for _ in 0..iter {
|
||||
let mut selector = jsonpath::Selector::default();
|
||||
let _ = selector.str_path(get_path());
|
||||
selector.value(&json);
|
||||
let r = selector.select();
|
||||
if r.is_err() {
|
||||
panic!();
|
||||
}
|
||||
// println!("{:?}", serde_json::to_string(&r.expect("")).unwrap());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user