From 22e854cc17d5552019a10c9c686deeb232899759 Mon Sep 17 00:00:00 2001 From: Alexander Slesarev Date: Tue, 18 Feb 2020 12:13:32 -0700 Subject: [PATCH] Go jsparser test has been added. --- README.md | 1 + json/build.sh | 9 +++++--- json/run.sh | 2 ++ json/test_jsparser.go | 48 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 json/test_jsparser.go diff --git a/README.md b/README.md index 37f55cb2..f0d42dad 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,7 @@ Testing parsing and simple calculating of values from a big JSON file. | V GCC | 2.06 ± 00.01 | 591.93 ± 00.05 | 53.57 ± 00.53 | | CPython UltraJSON | 2.13 ± 00.01 | 688.58 ± 01.48 | 67.03 ± 01.13 | | V Clang | 2.14 ± 00.01 | 592.50 ± 00.05 | 55.61 ± 00.51 | +| Go jsparser | 2.29 ± 00.03 | 221.28 ± 00.25 | 74.07 ± 01.27 | | Python | 2.36 ± 00.01 | 519.48 ± 00.06 | 63.15 ± 01.36 | | C++ json-c | 2.70 ± 00.01 | 1755.95 ± 00.04 | 69.74 ± 01.31 | | GCC Go | 2.74 ± 00.02 | 206.64 ± 00.40 | 68.64 ± 02.48 | diff --git a/json/build.sh b/json/build.sh index 2f78b6a4..9cca052a 100755 --- a/json/build.sh +++ b/json/build.sh @@ -87,9 +87,8 @@ v -prod -cc clang -o json_v_clang test.v go get github.com/json-iterator/go go build -o json_iter_go test_jsoniter.go -if [ ! -f /tmp/1.json ]; then - ruby generate_json.rb -fi +go get github.com/tamerh/jsparser +go build -o json_jsparser_go test_jsparser.go if [ ! -d ./daw_json_link_all ]; then git clone --depth 1 https://github.com/beached/daw_json_link.git ./daw_json_link_all/daw_json_link @@ -97,3 +96,7 @@ if [ ! -d ./daw_json_link_all ]; then git clone --depth 1 https://github.com/beached/utf_range.git ./daw_json_link_all/utf_range fi g++ -std=c++17 -O3 -L /usr/local/lib -I /usr/local/include -I./daw_json_link_all/daw_json_link/include -I./daw_json_link_all/header_libraries/include -I./daw_json_link_all/utf_range/include test_dawjsonlink.cpp -o json_dawjsonlink_cpp -I../common/libnotify -L../common/libnotify -lnotify + +if [ ! -f /tmp/1.json ]; then + ruby generate_json.rb +fi diff --git a/json/run.sh b/json/run.sh index 75a0082c..0aedb361 100755 --- a/json/run.sh +++ b/json/run.sh @@ -19,6 +19,8 @@ echo Go ../xtime.rb ./json_go echo Go jsoniter ../xtime.rb ./json_iter_go +echo Go jsparser +../xtime.rb ./json_jsparser_go echo GccGo ../xtime.rb ./json_go_gccgo echo D DMD diff --git a/json/test_jsparser.go b/json/test_jsparser.go new file mode 100644 index 00000000..8757c9b1 --- /dev/null +++ b/json/test_jsparser.go @@ -0,0 +1,48 @@ +package main + +import ( + "bufio" + "bytes" + "fmt" + "github.com/tamerh/jsparser" + "io/ioutil" + "net" + "os" + "strconv" +) + +func notify(msg string) { + conn, err := net.Dial("tcp", "localhost:9001") + if err == nil { + fmt.Fprintf(conn, msg) + conn.Close() + } +} + +func main() { + content, err := ioutil.ReadFile("/tmp/1.json") + if err != nil { + panic(fmt.Sprintf("%v", err)) + } + + notify(fmt.Sprintf("Go jsparser\t%d", os.Getpid())) + + f := bytes.NewReader(content) + br := bufio.NewReaderSize(f, 16384) + parser := jsparser.NewJSONParser(br, "coordinates").SkipProps([]string{"name", "opts"}) + x, y, z := 0.0, 0.0, 0.0 + len := 0.0 + + for json := range parser.Stream() { + xx, _ := strconv.ParseFloat(json.ObjectVals["x"].StringVal, 64) + yy, _ := strconv.ParseFloat(json.ObjectVals["y"].StringVal, 64) + zz, _ := strconv.ParseFloat(json.ObjectVals["z"].StringVal, 64) + x += xx + y += yy + z += zz + len += 1.0 + } + fmt.Printf("%.8f\n%.8f\n%.8f\n", x/len, y/len, z/len) + + notify("stop") +}