2 # This file is part of NIT ( http://www.nitlanguage.org ).
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # Shell script to bench json parsers over different documents
18 source ..
/bench_common.sh
19 source ..
/bench_plot.sh
21 ## CONFIGURATION OPTIONS ##
23 # Default number of times a command must be run with bench_command
24 # Can be overrided with 'the option -n'
31 echo "Preparing submodules"
32 git submodule update
--init
33 echo "Submodules ready"
35 echo "Preparing data for benchmarks"
36 if [ ! -e inputs
/large_escaped.json
]; then
37 echo "Downloading file 1/4"
38 wget
-O inputs
/large_escaped.json https
://github.com
/seductiveapps
/largeJSON
/blob
/master
/100mb.json?raw
=true
41 if [ ! -e inputs
/magic.json
]; then
42 echo "Downloading file 2/4"
43 wget
-O inputs
/magic.json http
://mtgjson.com
/json
/AllSets
-x.json
46 if [ ! -e inputs
/big_twitter.json
]; then
47 echo "Downloading file 3/4"
48 wget
-O inputs
/twitter.json https
://github.com
/miloyip
/nativejson
-benchmark
/raw
/master
/data
/twitter.json
55 if [ ! -e inputs
/big_gov_data.json
]; then
56 echo "Downloading file 4/4"
57 wget
-O inputs
/gov_data.json https
://edg.epa.gov
/data.json
68 echo "run_bench: ./bench_json.sh [options]"
69 echo " -v: verbose mode"
70 echo " -n count: number of execution for each bar (default: $count)"
71 echo " -fast: check only Nit"
77 while [ "$stop" = false
]; do
79 -v
) verbose
=true
; shift;;
80 --fast
) fast
=true
; shift;;
82 -n
) count
="$2"; shift; shift;;
91 echo >"$html" "<html><head></head><body>"
93 echo "Compiling engines"
95 if [ -z
"$fast" ]; then
96 declare -a script_names
=('C' 'Python 3' 'Python 2' 'Go' 'Nit Ad-hoc UTF-8 No Ropes' 'Nit Ad-hoc UTF-8 + Ropes' 'Ruby ext')
97 declare -a script_cmds
=('./scripts/c_parser' 'python3 scripts/python.py' 'python2 scripts/python.py' './scripts/json_parse' './scripts/nit_adhoc_utf_noropes' './scripts/nit_adhoc_utf_ropes' 'ruby scripts/json_ext.rb')
101 gcc
-O2
-I thirdparty
/ujson4c
/src
-I thirdparty
/ujson4c
/3rdparty
/ thirdparty
/ujson4c
/3rdparty
/ultrajsondec.c scripts
/c_parser.c
-o scripts
/c_parser
-lm
103 echo "Go JSON Parser"
105 go build
-o scripts
/json_parse scripts
/json_parse.go
107 declare -a script_names
=('Nit Ad-hoc UTF-8 No Ropes' 'Nit Ad-hoc UTF-8 + Ropes')
108 declare -a script_cmds
=('./scripts/nit_adhoc_utf_noropes' './scripts/nit_adhoc_utf_ropes')
112 echo "Nit/NitCC Parser"
114 nitc
--semi
-global scripts
/nitcc_parser.nit
-o scripts
/nitcc_parser
116 echo "Nit/Ad-Hoc UTF-8 Parser, No Ropes"
118 nitc
--semi
-global scripts
/nit_adhoc_utf_noropes.nit
-o scripts
/nit_adhoc_utf_noropes
120 echo "Nit/Ad-Hoc UTF-8 Parser, With Ropes"
122 nitc
--semi
-global scripts
/nit_adhoc_utf_ropes.nit
-o scripts
/nit_adhoc_utf_ropes
125 for script in `seq 1 ${#script_cmds[@]}`; do
126 echo "Preparing res for ${script_names[$script - 1]}"
127 prepare_res
"./out/${script_names[$script - 1]}.dat" "${script_names[$script - 1]}" "${script_names[$script - 1]}"
128 for file in inputs
/*.json
; do
129 fname
=`basename $file .json`
130 bench_command
$file "Benching file $file using ${script_cmds[$script - 1]} parser" ${script_cmds[$script - 1]} $file
134 rm scripts
/nitcc_parser
135 rm scripts
/json_parse
137 rm scripts
/nit_adhoc_utf_noropes
138 rm scripts
/nit_adhoc_utf_ropes
140 plot out
/bench_json.gnu
142 echo >>"$html" "</body></html>"
144 if test -n
"$died"; then
145 echo "Some commands failed"