빌드패스에서 'benchs' 제거

This commit is contained in:
freestrings 2019-06-26 16:33:58 +09:00
parent 8f01598e05
commit 3d33e8bd08
29 changed files with 79 additions and 50 deletions

View File

@ -14,7 +14,7 @@ branches:
matrix: matrix:
include: include:
- rust: nightly - rust: stable
os: linux os: linux
env: RUST_BACKTRACE=1 env: RUST_BACKTRACE=1
before_cache: | before_cache: |
@ -31,6 +31,7 @@ matrix:
- cargo test --verbose --all - cargo test --verbose --all
- cd wasm && cargo clippy -- -D warnings -A clippy::suspicious_else_formatting - cd wasm && cargo clippy -- -D warnings -A clippy::suspicious_else_formatting
- cd ../nodejs/native && cargo clippy -- -D warnings - cd ../nodejs/native && cargo clippy -- -D warnings
- cd ../../
after_success: | after_success: |
cargo tarpaulin --exclude-files nodejs wasm parser/mod.rs --out Xml cargo tarpaulin --exclude-files nodejs wasm parser/mod.rs --out Xml
bash <(curl -s https://codecov.io/bash) bash <(curl -s https://codecov.io/bash)

View File

@ -24,9 +24,6 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0", features = ["preserve_order"] } serde_json = { version = "1.0", features = ["preserve_order"] }
array_tool = "1.0.3" array_tool = "1.0.3"
[dev-dependencies]
bencher = "0.1.5"
[lib] [lib]
name = "jsonpath_lib" name = "jsonpath_lib"
path = "src/lib.rs" path = "src/lib.rs"

9
bench.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
set -e
#
# rustup default nightly
#
cargo bench --manifest-path ./benchmark/Cargo.toml

4
benchmark/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
.idea/*
.vscode
/target/
Cargo.lock

17
benchmark/Cargo.toml Normal file
View File

@ -0,0 +1,17 @@
[package]
name = "jsonpath_lib_benches"
version = "0.1.0"
authors = ["Changseok Han <freestrings@gmail.com>"]
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"

View File

@ -22,7 +22,7 @@ fn read_json(path: &str) -> String {
} }
fn get_string() -> String { fn get_string() -> String {
read_json("./benches/example.json") read_json("./example.json")
} }
fn get_json() -> Value { fn get_json() -> Value {

View File

@ -19,7 +19,7 @@ fn read_json(path: &str) -> String {
} }
fn get_string() -> String { fn get_string() -> String {
read_json("./benches/example.json") read_json("./example.json")
} }
fn get_json() -> Value { fn get_json() -> Value {

1
benchmark/src/main.rs Normal file
View File

@ -0,0 +1 @@
fn main() {}

View File

@ -11,7 +11,7 @@ WASM_BROWSER_PKG="${WASM}"/browser_pkg
WASM_NODEJS_PKG="${WASM}"/nodejs_pkg WASM_NODEJS_PKG="${WASM}"/nodejs_pkg
WASM_ALL_PKG="${WASM}"/all_pkg WASM_ALL_PKG="${WASM}"/all_pkg
WASM_TEST="${WASM}"/tests WASM_TEST="${WASM}"/tests
BENCHES="${DIR}"/benches BENCHES="${DIR}"/benchmark
BENCHES_JS="${BENCHES}"/javascript BENCHES_JS="${BENCHES}"/javascript
NODEJS="${DIR}"/nodejs NODEJS="${DIR}"/nodejs
DOCS="${DIR}"/docs DOCS="${DIR}"/docs

View File

@ -13,7 +13,7 @@ fn array() {
select_and_then_compare( select_and_then_compare(
"$.school.friends[1, 2]", "$.school.friends[1, 2]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([ json!([
{"id": 1, "name": "Vincent Cannon" }, {"id": 1, "name": "Vincent Cannon" },
{"id": 2, "name": "Gray Berry"} {"id": 2, "name": "Gray Berry"}
@ -22,7 +22,7 @@ fn array() {
select_and_then_compare( select_and_then_compare(
"$.school.friends[1: ]", "$.school.friends[1: ]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([ json!([
{"id": 1, "name": "Vincent Cannon" }, {"id": 1, "name": "Vincent Cannon" },
{"id": 2, "name": "Gray Berry"} {"id": 2, "name": "Gray Berry"}
@ -31,7 +31,7 @@ fn array() {
select_and_then_compare( select_and_then_compare(
"$.school.friends[:-2]", "$.school.friends[:-2]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([ json!([
{"id": 0, "name": "Millicent Norman"} {"id": 0, "name": "Millicent Norman"}
]), ]),
@ -39,13 +39,13 @@ fn array() {
select_and_then_compare( select_and_then_compare(
"$..friends[2].name", "$..friends[2].name",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!(["Gray Berry", "Gray Berry"]), json!(["Gray Berry", "Gray Berry"]),
); );
select_and_then_compare( select_and_then_compare(
"$..friends[*].name", "$..friends[*].name",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([ json!([
"Vincent Cannon", "Vincent Cannon",
"Gray Berry", "Gray Berry",
@ -57,19 +57,19 @@ fn array() {
select_and_then_compare( select_and_then_compare(
"$['school']['friends'][*].['name']", "$['school']['friends'][*].['name']",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!(["Millicent Norman", "Vincent Cannon", "Gray Berry"]), json!(["Millicent Norman", "Vincent Cannon", "Gray Berry"]),
); );
select_and_then_compare( select_and_then_compare(
"$['school']['friends'][0].['name']", "$['school']['friends'][0].['name']",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!(["Millicent Norman"]), json!(["Millicent Norman"]),
); );
select_and_then_compare( select_and_then_compare(
r#"$.["eyeColor", "name"]"#, r#"$.["eyeColor", "name"]"#,
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!(["blue", "Leonor Herman"]), json!(["blue", "Leonor Herman"]),
); );
} }
@ -80,7 +80,7 @@ fn return_type() {
select_and_then_compare( select_and_then_compare(
"$.school", "$.school",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([{ json!([{
"friends": [ "friends": [
{"id": 0, "name": "Millicent Norman"}, {"id": 0, "name": "Millicent Norman"},
@ -92,7 +92,7 @@ fn return_type() {
select_and_then_compare( select_and_then_compare(
"$.school[?(@.friends[0])]", "$.school[?(@.friends[0])]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([{ json!([{
"friends": [ "friends": [
{"id": 0, "name": "Millicent Norman"}, {"id": 0, "name": "Millicent Norman"},
@ -104,7 +104,7 @@ fn return_type() {
select_and_then_compare( select_and_then_compare(
"$.school[?(@.friends[10])]", "$.school[?(@.friends[10])]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([{ json!([{
"friends": [ "friends": [
{"id": 0, "name": "Millicent Norman"}, {"id": 0, "name": "Millicent Norman"},
@ -116,7 +116,7 @@ fn return_type() {
select_and_then_compare( select_and_then_compare(
"$.school[?(1==1)]", "$.school[?(1==1)]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([{ json!([{
"friends": [ "friends": [
{"id": 0, "name": "Millicent Norman"}, {"id": 0, "name": "Millicent Norman"},
@ -128,7 +128,7 @@ fn return_type() {
select_and_then_compare( select_and_then_compare(
"$.school.friends[?(1==1)]", "$.school.friends[?(1==1)]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([[ json!([[
{"id": 0, "name": "Millicent Norman"}, {"id": 0, "name": "Millicent Norman"},
{"id": 1, "name": "Vincent Cannon" }, {"id": 1, "name": "Vincent Cannon" },
@ -143,7 +143,7 @@ fn op_default() {
select_and_then_compare( select_and_then_compare(
"$.school[?(@.friends == @.friends)]", "$.school[?(@.friends == @.friends)]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([{ json!([{
"friends": [ "friends": [
{"id": 0, "name": "Millicent Norman"}, {"id": 0, "name": "Millicent Norman"},
@ -155,7 +155,7 @@ fn op_default() {
select_and_then_compare( select_and_then_compare(
"$.friends[?(@.name)]", "$.friends[?(@.name)]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([ json!([
{ "id" : 1, "name" : "Vincent Cannon" }, { "id" : 1, "name" : "Vincent Cannon" },
{ "id" : 2, "name" : "Gray Berry" } { "id" : 2, "name" : "Gray Berry" }
@ -164,7 +164,7 @@ fn op_default() {
select_and_then_compare( select_and_then_compare(
"$.friends[?(@.id >= 2)]", "$.friends[?(@.id >= 2)]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([ json!([
{ "id" : 2, "name" : "Gray Berry" } { "id" : 2, "name" : "Gray Berry" }
]), ]),
@ -172,7 +172,7 @@ fn op_default() {
select_and_then_compare( select_and_then_compare(
"$.friends[?(@.id >= 2 || @.id == 1)]", "$.friends[?(@.id >= 2 || @.id == 1)]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([ json!([
{ "id" : 2, "name" : "Gray Berry" }, { "id" : 2, "name" : "Gray Berry" },
{ "id" : 1, "name" : "Vincent Cannon" } { "id" : 1, "name" : "Vincent Cannon" }
@ -181,25 +181,25 @@ fn op_default() {
select_and_then_compare( select_and_then_compare(
"$.friends[?( (@.id >= 2 || @.id == 1) && @.id == 0)]", "$.friends[?( (@.id >= 2 || @.id == 1) && @.id == 0)]",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([Value::Null]), json!([Value::Null]),
); );
select_and_then_compare( select_and_then_compare(
"$..friends[?(@.id == $.index)].id", "$..friends[?(@.id == $.index)].id",
read_json("./benches/data_obj.json"), read_json("./benchmark/data_obj.json"),
json!([0, 0]), json!([0, 0]),
); );
select_and_then_compare( select_and_then_compare(
"$..book[?($.store.bicycle.price < @.price)].price", "$..book[?($.store.bicycle.price < @.price)].price",
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([22.99]), json!([22.99]),
); );
select_and_then_compare( select_and_then_compare(
"$..book[?( (@.price == 12.99 || @.category == 'reference') && @.price > 10)].price", "$..book[?( (@.price == 12.99 || @.category == 'reference') && @.price > 10)].price",
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([12.99]), json!([12.99]),
); );
@ -365,7 +365,7 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$.store.book[*].author"#, r#"$.store.book[*].author"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([ json!([
"Nigel Rees", "Nigel Rees",
"Evelyn Waugh", "Evelyn Waugh",
@ -376,7 +376,7 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$..author"#, r#"$..author"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([ json!([
"Nigel Rees", "Nigel Rees",
"Evelyn Waugh", "Evelyn Waugh",
@ -387,7 +387,7 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$.store.*"#, r#"$.store.*"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([ json!([
[ [
{"category" : "reference", "author" : "Nigel Rees","title" : "Sayings of the Century", "price" : 8.95}, {"category" : "reference", "author" : "Nigel Rees","title" : "Sayings of the Century", "price" : 8.95},
@ -401,13 +401,13 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$.store..price"#, r#"$.store..price"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([8.95, 12.99, 8.99, 22.99, 19.95]), json!([8.95, 12.99, 8.99, 22.99, 19.95]),
); );
select_and_then_compare( select_and_then_compare(
r#"$..book[2]"#, r#"$..book[2]"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([ json!([
{ {
"category" : "fiction", "category" : "fiction",
@ -421,7 +421,7 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$..book[-2]"#, r#"$..book[-2]"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([ json!([
{ {
"category" : "fiction", "category" : "fiction",
@ -435,7 +435,7 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$..book[0, 1]"#, r#"$..book[0, 1]"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([ json!([
{ {
"category" : "reference", "category" : "reference",
@ -454,7 +454,7 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$..book[:2]"#, r#"$..book[:2]"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([ json!([
{ {
"category" : "reference", "category" : "reference",
@ -473,7 +473,7 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$..book[2:]"#, r#"$..book[2:]"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([ json!([
{ {
"category" : "fiction", "category" : "fiction",
@ -494,7 +494,7 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$..book[?(@.isbn)]"#, r#"$..book[?(@.isbn)]"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([ json!([
{ {
"category" : "fiction", "category" : "fiction",
@ -515,7 +515,7 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$.store.book[?(@.price < 10)]"#, r#"$.store.book[?(@.price < 10)]"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
json!([ json!([
{ {
"category" : "reference", "category" : "reference",
@ -535,8 +535,8 @@ fn example() {
select_and_then_compare( select_and_then_compare(
r#"$..*"#, r#"$..*"#,
read_json("./benches/example.json"), read_json("./benchmark/example.json"),
read_json("./benches/giveme_every_thing_result.json"), read_json("./benchmark/giveme_every_thing_result.json"),
); );
} }
@ -651,7 +651,7 @@ fn all_filter() {
for path in &[r#"$..friends.*"#, r#"$[*].friends.*"#] { for path in &[r#"$..friends.*"#, r#"$[*].friends.*"#] {
select_and_then_compare( select_and_then_compare(
path, path,
read_json("./benches/data_array.json"), read_json("./benchmark/data_array.json"),
json!([ json!([
{ "id" : 0, "name" : "Millicent Norman" }, { "id" : 0, "name" : "Millicent Norman" },
{ "id" : 1, "name" : "Vincent Cannon" }, { "id" : 1, "name" : "Vincent Cannon" },

View File

@ -15,7 +15,7 @@ mod common;
fn compile() { fn compile() {
let compile_object = |path| { let compile_object = |path| {
let mut template = jsonpath::compile(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 json = template(&json_obj).unwrap();
let ret = json!([ let ret = json!([
{"id": 2,"name": "Gray Berry"}, {"id": 2,"name": "Gray Berry"},
@ -26,7 +26,7 @@ fn compile() {
let compile_array = |path| { let compile_array = |path| {
let mut template = jsonpath::compile(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 json = template(&json_obj).unwrap();
let ret = json!([ let ret = json!([
{"id": 2,"name": "Gray Berry"}, {"id": 2,"name": "Gray Berry"},
@ -59,7 +59,7 @@ fn selector() {
compare_result(json, target); 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); let mut selector = jsonpath::selector(&json_obj);
select( select(
@ -96,7 +96,7 @@ fn selector_as() {
assert_eq!(json, target); 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::<Friend>(&json_obj); let mut selector = jsonpath::selector_as::<Friend>(&json_obj);
select( select(
@ -129,7 +129,7 @@ fn selector_as() {
#[test] #[test]
fn select() { 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 json = jsonpath::select(&json_obj, "$..book[2]").unwrap();
let ret = json!([{ let ret = json!([{
"category" : "fiction", "category" : "fiction",
@ -143,7 +143,7 @@ fn select() {
#[test] #[test]
fn select_str() { 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 result_str = jsonpath::select_as_str(&json_str, "$..book[2]").unwrap();
let ret = json!([{ let ret = json!([{
"category" : "fiction", "category" : "fiction",

View File

@ -482,7 +482,7 @@ fn readme_delete() {
#[test] #[test]
fn readme_delete2() { 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(); let ret = jsonpath::delete(json_obj, "$.store.book").unwrap();

View File

@ -18,7 +18,7 @@ fn selector_mut() {
let result = selector_mut let result = selector_mut
.str_path(r#"$.store..price"#) .str_path(r#"$.store..price"#)
.unwrap() .unwrap()
.value(read_json("./benches/example.json")) .value(read_json("./benchmark/example.json"))
.replace_with(&mut |v| { .replace_with(&mut |v| {
if let Value::Number(n) = v { if let Value::Number(n) = v {
nums.push(n.as_f64().unwrap()); nums.push(n.as_f64().unwrap());