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)"
75 while [ "$stop" = false
]; do
77 -v
) verbose
=true
; shift;;
79 -n
) count
="$2"; shift; shift;;
88 echo "Compiling engines"
92 gcc
-O2
-I thirdparty
/ujson4c
/src
-I thirdparty
/ujson4c
/3rdparty
/ thirdparty
/ujson4c
/3rdparty
/ultrajsondec.c scripts
/c_parser.c
-o scripts
/c_parser
-lm
96 go build
-o scripts
/json_parse scripts
/json_parse.go
98 echo "Nit/NitCC Parser"
100 nitc
--semi
-global scripts
/nitcc_parser.nit
-o scripts
/nitcc_parser
102 echo "Nit/Ad-Hoc UTF-8 Parser, No Ropes"
104 nitc
--semi
-global scripts
/nit_adhoc_utf_noropes.nit
-o scripts
/nit_adhoc_utf_noropes
106 echo "Nit/Ad-Hoc UTF-8 Parser, With Ropes"
108 nitc
--semi
-global scripts
/nit_adhoc_utf_ropes.nit
-o scripts
/nit_adhoc_utf_ropes
110 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')
111 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')
113 for script in `seq 1 ${#script_cmds[@]}`; do
114 echo "Preparing res for ${script_names[$script - 1]}"
115 prepare_res
"./out/${script_names[$script - 1]}.dat" "${script_names[$script - 1]}" "${script_names[$script - 1]}"
116 for file in inputs
/*.json
; do
117 fname
=`basename $file .json`
118 bench_command
$file "Benching file $file using ${script_cmds[$script - 1]} parser" ${script_cmds[$script - 1]} $file
122 rm scripts
/nitcc_parser
123 rm scripts
/json_parse
125 rm scripts
/nit_adhoc_utf_noropes
126 rm scripts
/nit_adhoc_utf_ropes
128 plot out
/bench_json.gnu