diff --git a/.travis.yml b/.travis.yml index 66bee5a..38dbe91 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ branches: matrix: include: - - rust: nightly + - rust: stable os: linux env: RUST_BACKTRACE=1 before_cache: | @@ -31,6 +31,7 @@ matrix: - cargo test --verbose --all - cd wasm && cargo clippy -- -D warnings -A clippy::suspicious_else_formatting - cd ../nodejs/native && cargo clippy -- -D warnings + - cd ../../ after_success: | cargo tarpaulin --exclude-files nodejs wasm parser/mod.rs --out Xml bash <(curl -s https://codecov.io/bash) diff --git a/Cargo.toml b/Cargo.toml index 63d167d..857d030 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,9 +24,6 @@ serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0", features = ["preserve_order"] } array_tool = "1.0.3" -[dev-dependencies] -bencher = "0.1.5" - [lib] name = "jsonpath_lib" path = "src/lib.rs" diff --git a/bench.sh b/bench.sh new file mode 100755 index 0000000..669778c --- /dev/null +++ b/bench.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +# +# rustup default nightly +# + +cargo bench --manifest-path ./benchmark/Cargo.toml diff --git a/benchmark/.gitignore b/benchmark/.gitignore new file mode 100644 index 0000000..3343429 --- /dev/null +++ b/benchmark/.gitignore @@ -0,0 +1,4 @@ +.idea/* +.vscode +/target/ +Cargo.lock \ No newline at end of file diff --git a/benchmark/Cargo.toml b/benchmark/Cargo.toml new file mode 100644 index 0000000..fd5f6b2 --- /dev/null +++ b/benchmark/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "jsonpath_lib_benches" +version = "0.1.0" +authors = ["Changseok Han "] +description = "jsonpath_lib benchmark" +license = "MIT" +[dependencies] +serde = { version = "1.0", features = ["derive"] } +serde_json = { version = "1.0", features = ["preserve_order"] } +jsonpath_lib = { path = "../" } + +[dev-dependencies] +bencher = "0.1.5" + +[[bin]] +name = "jsonpath_lib_benches" +path = "src/main.rs" \ No newline at end of file diff --git a/benches/bench_bin/.gitignore b/benchmark/bench_bin/.gitignore similarity index 100% rename from benches/bench_bin/.gitignore rename to benchmark/bench_bin/.gitignore diff --git a/benches/bench_bin/Cargo.toml b/benchmark/bench_bin/Cargo.toml similarity index 100% rename from benches/bench_bin/Cargo.toml rename to benchmark/bench_bin/Cargo.toml diff --git a/benches/bench_bin/bench.sh b/benchmark/bench_bin/bench.sh similarity index 100% rename from benches/bench_bin/bench.sh rename to benchmark/bench_bin/bench.sh diff --git a/benches/bench_bin/src/main.rs b/benchmark/bench_bin/src/main.rs similarity index 100% rename from benches/bench_bin/src/main.rs rename to benchmark/bench_bin/src/main.rs diff --git a/benches/bench_native.sh b/benchmark/bench_native.sh similarity index 100% rename from benches/bench_native.sh rename to benchmark/bench_native.sh diff --git a/benches/bench_wasm.sh b/benchmark/bench_wasm.sh similarity index 100% rename from benches/bench_wasm.sh rename to benchmark/bench_wasm.sh diff --git a/benches/bench.rs b/benchmark/benches/bench.rs similarity index 98% rename from benches/bench.rs rename to benchmark/benches/bench.rs index b2907b8..9cea0ea 100644 --- a/benches/bench.rs +++ b/benchmark/benches/bench.rs @@ -22,7 +22,7 @@ fn read_json(path: &str) -> String { } fn get_string() -> String { - read_json("./benches/example.json") + read_json("./example.json") } fn get_json() -> Value { diff --git a/benches/bench_example.rs b/benchmark/benches/bench_example.rs similarity index 96% rename from benches/bench_example.rs rename to benchmark/benches/bench_example.rs index 3cd3764..f91b7c2 100644 --- a/benches/bench_example.rs +++ b/benchmark/benches/bench_example.rs @@ -19,7 +19,7 @@ fn read_json(path: &str) -> String { } fn get_string() -> String { - read_json("./benches/example.json") + read_json("./example.json") } fn get_json() -> Value { diff --git a/benches/data_array.json b/benchmark/data_array.json similarity index 100% rename from benches/data_array.json rename to benchmark/data_array.json diff --git a/benches/data_obj.json b/benchmark/data_obj.json similarity index 100% rename from benches/data_obj.json rename to benchmark/data_obj.json diff --git a/benches/example.json b/benchmark/example.json similarity index 100% rename from benches/example.json rename to benchmark/example.json diff --git a/benches/giveme_every_thing_result.json b/benchmark/giveme_every_thing_result.json similarity index 100% rename from benches/giveme_every_thing_result.json rename to benchmark/giveme_every_thing_result.json diff --git a/benches/javascript/.gitignore b/benchmark/javascript/.gitignore similarity index 100% rename from benches/javascript/.gitignore rename to benchmark/javascript/.gitignore diff --git a/benches/javascript/bench.js b/benchmark/javascript/bench.js similarity index 100% rename from benches/javascript/bench.js rename to benchmark/javascript/bench.js diff --git a/benches/javascript/bench.sh b/benchmark/javascript/bench.sh similarity index 100% rename from benches/javascript/bench.sh rename to benchmark/javascript/bench.sh diff --git a/benches/javascript/package-lock.json b/benchmark/javascript/package-lock.json similarity index 100% rename from benches/javascript/package-lock.json rename to benchmark/javascript/package-lock.json diff --git a/benches/javascript/package.json b/benchmark/javascript/package.json similarity index 100% rename from benches/javascript/package.json rename to benchmark/javascript/package.json diff --git a/benches/package-lock.json b/benchmark/package-lock.json similarity index 100% rename from benches/package-lock.json rename to benchmark/package-lock.json diff --git a/benchmark/src/main.rs b/benchmark/src/main.rs new file mode 100644 index 0000000..e71fdf5 --- /dev/null +++ b/benchmark/src/main.rs @@ -0,0 +1 @@ +fn main() {} \ No newline at end of file diff --git a/build.sh b/build.sh index b9fbf00..cbb9198 100755 --- a/build.sh +++ b/build.sh @@ -11,7 +11,7 @@ WASM_BROWSER_PKG="${WASM}"/browser_pkg WASM_NODEJS_PKG="${WASM}"/nodejs_pkg WASM_ALL_PKG="${WASM}"/all_pkg WASM_TEST="${WASM}"/tests -BENCHES="${DIR}"/benches +BENCHES="${DIR}"/benchmark BENCHES_JS="${BENCHES}"/javascript NODEJS="${DIR}"/nodejs DOCS="${DIR}"/docs diff --git a/tests/filter.rs b/tests/filter.rs index 4540039..112cfd3 100644 --- a/tests/filter.rs +++ b/tests/filter.rs @@ -13,7 +13,7 @@ fn array() { select_and_then_compare( "$.school.friends[1, 2]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([ {"id": 1, "name": "Vincent Cannon" }, {"id": 2, "name": "Gray Berry"} @@ -22,7 +22,7 @@ fn array() { select_and_then_compare( "$.school.friends[1: ]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([ {"id": 1, "name": "Vincent Cannon" }, {"id": 2, "name": "Gray Berry"} @@ -31,7 +31,7 @@ fn array() { select_and_then_compare( "$.school.friends[:-2]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([ {"id": 0, "name": "Millicent Norman"} ]), @@ -39,13 +39,13 @@ fn array() { select_and_then_compare( "$..friends[2].name", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!(["Gray Berry", "Gray Berry"]), ); select_and_then_compare( "$..friends[*].name", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([ "Vincent Cannon", "Gray Berry", @@ -57,19 +57,19 @@ fn array() { select_and_then_compare( "$['school']['friends'][*].['name']", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!(["Millicent Norman", "Vincent Cannon", "Gray Berry"]), ); select_and_then_compare( "$['school']['friends'][0].['name']", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!(["Millicent Norman"]), ); select_and_then_compare( r#"$.["eyeColor", "name"]"#, - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!(["blue", "Leonor Herman"]), ); } @@ -80,7 +80,7 @@ fn return_type() { select_and_then_compare( "$.school", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([{ "friends": [ {"id": 0, "name": "Millicent Norman"}, @@ -92,7 +92,7 @@ fn return_type() { select_and_then_compare( "$.school[?(@.friends[0])]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([{ "friends": [ {"id": 0, "name": "Millicent Norman"}, @@ -104,7 +104,7 @@ fn return_type() { select_and_then_compare( "$.school[?(@.friends[10])]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([{ "friends": [ {"id": 0, "name": "Millicent Norman"}, @@ -116,7 +116,7 @@ fn return_type() { select_and_then_compare( "$.school[?(1==1)]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([{ "friends": [ {"id": 0, "name": "Millicent Norman"}, @@ -128,7 +128,7 @@ fn return_type() { select_and_then_compare( "$.school.friends[?(1==1)]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([[ {"id": 0, "name": "Millicent Norman"}, {"id": 1, "name": "Vincent Cannon" }, @@ -143,7 +143,7 @@ fn op_default() { select_and_then_compare( "$.school[?(@.friends == @.friends)]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([{ "friends": [ {"id": 0, "name": "Millicent Norman"}, @@ -155,7 +155,7 @@ fn op_default() { select_and_then_compare( "$.friends[?(@.name)]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([ { "id" : 1, "name" : "Vincent Cannon" }, { "id" : 2, "name" : "Gray Berry" } @@ -164,7 +164,7 @@ fn op_default() { select_and_then_compare( "$.friends[?(@.id >= 2)]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([ { "id" : 2, "name" : "Gray Berry" } ]), @@ -172,7 +172,7 @@ fn op_default() { select_and_then_compare( "$.friends[?(@.id >= 2 || @.id == 1)]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([ { "id" : 2, "name" : "Gray Berry" }, { "id" : 1, "name" : "Vincent Cannon" } @@ -181,25 +181,25 @@ fn op_default() { select_and_then_compare( "$.friends[?( (@.id >= 2 || @.id == 1) && @.id == 0)]", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([Value::Null]), ); select_and_then_compare( "$..friends[?(@.id == $.index)].id", - read_json("./benches/data_obj.json"), + read_json("./benchmark/data_obj.json"), json!([0, 0]), ); select_and_then_compare( "$..book[?($.store.bicycle.price < @.price)].price", - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([22.99]), ); select_and_then_compare( "$..book[?( (@.price == 12.99 || @.category == 'reference') && @.price > 10)].price", - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([12.99]), ); @@ -365,7 +365,7 @@ fn example() { select_and_then_compare( r#"$.store.book[*].author"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([ "Nigel Rees", "Evelyn Waugh", @@ -376,7 +376,7 @@ fn example() { select_and_then_compare( r#"$..author"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([ "Nigel Rees", "Evelyn Waugh", @@ -387,7 +387,7 @@ fn example() { select_and_then_compare( r#"$.store.*"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([ [ {"category" : "reference", "author" : "Nigel Rees","title" : "Sayings of the Century", "price" : 8.95}, @@ -401,13 +401,13 @@ fn example() { select_and_then_compare( r#"$.store..price"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([8.95, 12.99, 8.99, 22.99, 19.95]), ); select_and_then_compare( r#"$..book[2]"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([ { "category" : "fiction", @@ -421,7 +421,7 @@ fn example() { select_and_then_compare( r#"$..book[-2]"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([ { "category" : "fiction", @@ -435,7 +435,7 @@ fn example() { select_and_then_compare( r#"$..book[0, 1]"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([ { "category" : "reference", @@ -454,7 +454,7 @@ fn example() { select_and_then_compare( r#"$..book[:2]"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([ { "category" : "reference", @@ -473,7 +473,7 @@ fn example() { select_and_then_compare( r#"$..book[2:]"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([ { "category" : "fiction", @@ -494,7 +494,7 @@ fn example() { select_and_then_compare( r#"$..book[?(@.isbn)]"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([ { "category" : "fiction", @@ -515,7 +515,7 @@ fn example() { select_and_then_compare( r#"$.store.book[?(@.price < 10)]"#, - read_json("./benches/example.json"), + read_json("./benchmark/example.json"), json!([ { "category" : "reference", @@ -535,8 +535,8 @@ fn example() { select_and_then_compare( r#"$..*"#, - read_json("./benches/example.json"), - read_json("./benches/giveme_every_thing_result.json"), + read_json("./benchmark/example.json"), + read_json("./benchmark/giveme_every_thing_result.json"), ); } @@ -651,7 +651,7 @@ fn all_filter() { for path in &[r#"$..friends.*"#, r#"$[*].friends.*"#] { select_and_then_compare( path, - read_json("./benches/data_array.json"), + read_json("./benchmark/data_array.json"), json!([ { "id" : 0, "name" : "Millicent Norman" }, { "id" : 1, "name" : "Vincent Cannon" }, diff --git a/tests/lib.rs b/tests/lib.rs index 1ee8780..5ed8fc4 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -15,7 +15,7 @@ mod common; fn compile() { let compile_object = |path| { let mut template = jsonpath::compile(path); - let json_obj = read_json("./benches/data_obj.json"); + let json_obj = read_json("./benchmark/data_obj.json"); let json = template(&json_obj).unwrap(); let ret = json!([ {"id": 2,"name": "Gray Berry"}, @@ -26,7 +26,7 @@ fn compile() { let compile_array = |path| { let mut template = jsonpath::compile(path); - let json_obj = read_json("./benches/data_array.json"); + let json_obj = read_json("./benchmark/data_array.json"); let json = template(&json_obj).unwrap(); let ret = json!([ {"id": 2,"name": "Gray Berry"}, @@ -59,7 +59,7 @@ fn selector() { compare_result(json, target); }; - let json_obj = read_json("./benches/data_obj.json"); + let json_obj = read_json("./benchmark/data_obj.json"); let mut selector = jsonpath::selector(&json_obj); select( @@ -96,7 +96,7 @@ fn selector_as() { assert_eq!(json, target); }; - let json_obj = read_json("./benches/data_obj.json"); + let json_obj = read_json("./benchmark/data_obj.json"); let mut selector = jsonpath::selector_as::(&json_obj); select( @@ -129,7 +129,7 @@ fn selector_as() { #[test] fn select() { - let json_obj = read_json("./benches/example.json"); + let json_obj = read_json("./benchmark/example.json"); let json = jsonpath::select(&json_obj, "$..book[2]").unwrap(); let ret = json!([{ "category" : "fiction", @@ -143,7 +143,7 @@ fn select() { #[test] fn select_str() { - let json_str = read_contents("./benches/example.json"); + let json_str = read_contents("./benchmark/example.json"); let result_str = jsonpath::select_as_str(&json_str, "$..book[2]").unwrap(); let ret = json!([{ "category" : "fiction", diff --git a/tests/readme.rs b/tests/readme.rs index 2ca2274..ae2a02c 100644 --- a/tests/readme.rs +++ b/tests/readme.rs @@ -482,7 +482,7 @@ fn readme_delete() { #[test] fn readme_delete2() { - let json_obj = common::read_json("./benches/example.json"); + let json_obj = common::read_json("./benchmark/example.json"); let ret = jsonpath::delete(json_obj, "$.store.book").unwrap(); diff --git a/tests/selector.rs b/tests/selector.rs index 7be7ea4..c8f2da8 100644 --- a/tests/selector.rs +++ b/tests/selector.rs @@ -18,7 +18,7 @@ fn selector_mut() { let result = selector_mut .str_path(r#"$.store..price"#) .unwrap() - .value(read_json("./benches/example.json")) + .value(read_json("./benchmark/example.json")) .replace_with(&mut |v| { if let Value::Number(n) = v { nums.push(n.as_f64().unwrap());