Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go jsparser test has been added. #236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
9 changes: 6 additions & 3 deletions json/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ 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
git clone --depth 1 https://github.com/beached/header_libraries.git ./daw_json_link_all/header_libraries
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
2 changes: 2 additions & 0 deletions json/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions json/test_jsparser.go
Original file line number Diff line number Diff line change
@@ -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")
}