lib/core/stream: LineIterator use CachedIterator
[nit.git] / benchmarks / json / bench_json.sh
1 #!/bin/bash
2 # This file is part of NIT ( http://www.nitlanguage.org ).
3 #
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
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
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.
15
16 # Shell script to bench json parsers over different documents
17
18 source ../bench_common.sh
19 source ../bench_plot.sh
20
21 ## CONFIGURATION OPTIONS ##
22
23 # Default number of times a command must be run with bench_command
24 # Can be overrided with 'the option -n'
25 count=5
26
27 ## HANDLE OPTIONS ##
28
29 function init_repo()
30 {
31 echo "Preparing submodules"
32 git submodule update --init
33 echo "Submodules ready"
34 mkdir -p inputs
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
39 fi
40 echo "File 1/4 ready"
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
44 fi
45 echo "File 2/4 ready"
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
49 cd inputs
50 ./multiply_twitter.sh
51 rm twitter.json
52 cd ..
53 fi
54 echo "File 3/4 ready"
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
58 cd inputs
59 ./multiply_gov.sh
60 rm gov_data.json
61 cd ..
62 fi
63 echo "File 4/4 ready"
64 }
65
66 function usage()
67 {
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"
72 echo " -h: this help"
73 }
74
75 stop=false
76 fast=
77 while [ "$stop" = false ]; do
78 case "$1" in
79 -v) verbose=true; shift;;
80 --fast) fast=true; shift;;
81 -h) usage; exit;;
82 -n) count="$2"; shift; shift;;
83 *) stop=true
84 esac
85 done
86
87 init_repo
88
89 mkdir -p out
90 html="index.html"
91 echo >"$html" "<html><head></head><body>"
92
93 echo "Compiling engines"
94
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')
98
99 echo "C JSON Parser"
100
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
102
103 echo "Go JSON Parser"
104
105 go build -o scripts/json_parse scripts/json_parse.go
106 else
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')
109
110 fi
111
112 echo "Nit/NitCC Parser"
113
114 nitc --semi-global scripts/nitcc_parser.nit -o scripts/nitcc_parser
115
116 echo "Nit/Ad-Hoc UTF-8 Parser, No Ropes"
117
118 nitc --semi-global scripts/nit_adhoc_utf_noropes.nit -o scripts/nit_adhoc_utf_noropes
119
120 echo "Nit/Ad-Hoc UTF-8 Parser, With Ropes"
121
122 nitc --semi-global scripts/nit_adhoc_utf_ropes.nit -o scripts/nit_adhoc_utf_ropes
123
124
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
131 done;
132 done;
133
134 rm scripts/nitcc_parser
135 rm scripts/json_parse
136 rm scripts/c_parser
137 rm scripts/nit_adhoc_utf_noropes
138 rm scripts/nit_adhoc_utf_ropes
139
140 plot out/bench_json.gnu
141
142 echo >>"$html" "</body></html>"
143
144 if test -n "$died"; then
145 echo "Some commands failed"
146 exit 1
147 fi
148 exit 0