mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-06-13 08:01:26 +00:00
first commit lua ffi
This commit is contained in:
4
benchmark/benches_lua_vs_rust/.gitignore
vendored
Normal file
4
benchmark/benches_lua_vs_rust/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
.idea/*
|
||||
.vscode
|
||||
/target/
|
||||
Cargo.lock
|
13
benchmark/benches_lua_vs_rust/Cargo.toml
Normal file
13
benchmark/benches_lua_vs_rust/Cargo.toml
Normal file
@ -0,0 +1,13 @@
|
||||
[package]
|
||||
name = "lua_vs_rust_benchmark"
|
||||
version = "0.1.0"
|
||||
authors = ["Changseok Han <freestrings@gmail.com>"]
|
||||
license = "MIT"
|
||||
[dependencies]
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = { version = "1.0", features = ["preserve_order"] }
|
||||
jsonpath_lib = { path = "../../" }
|
||||
|
||||
[[bin]]
|
||||
name = "lua_vs_rust_benchmark"
|
||||
path = "example.rs"
|
25
benchmark/benches_lua_vs_rust/bench_lua_vs_rust.sh
Executable file
25
benchmark/benches_lua_vs_rust/bench_lua_vs_rust.sh
Executable file
@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# http://luajit.org/index.html
|
||||
|
||||
cargo clean && \
|
||||
cargo build --release
|
||||
|
||||
export JSONPATH_LIB_PATH="${PWD}/../../target/release"
|
||||
export LUA_PATH="${PWD}/../../lua/?.lua;"
|
||||
|
||||
echo
|
||||
time cargo run --release -- 1000
|
||||
echo
|
||||
time luajit example.lua 1000
|
||||
echo
|
||||
time cargo run --release -- 5000
|
||||
echo
|
||||
time luajit example.lua 5000
|
||||
echo
|
||||
time cargo run --release -- 10000
|
||||
echo
|
||||
time luajit example.lua 10000
|
||||
|
20
benchmark/benches_lua_vs_rust/example.lua
Normal file
20
benchmark/benches_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 cb = compile("$..book[?(@.price<30 && @.category==\"fiction\")]");
|
||||
for i = 0, iter do
|
||||
local r = cb(data);
|
||||
-- print(r);
|
||||
end
|
46
benchmark/benches_lua_vs_rust/example.rs
Normal file
46
benchmark/benches_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());
|
||||
}
|
||||
}
|
0
benchmark/benches_lua_vs_rust/lib.rs
Normal file
0
benchmark/benches_lua_vs_rust/lib.rs
Normal file
Reference in New Issue
Block a user