|
| 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 " -h: this help" |
| 72 | +} |
| 73 | + |
| 74 | +stop=false |
| 75 | +while [ "$stop" = false ]; do |
| 76 | + case "$1" in |
| 77 | + -v) verbose=true; shift;; |
| 78 | + -h) usage; exit;; |
| 79 | + -n) count="$2"; shift; shift;; |
| 80 | + *) stop=true |
| 81 | + esac |
| 82 | +done |
| 83 | + |
| 84 | +init_repo |
| 85 | + |
| 86 | +mkdir -p out |
| 87 | + |
| 88 | +echo "Compiling engines" |
| 89 | + |
| 90 | +echo "C JSON Parser" |
| 91 | + |
| 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 |
| 93 | + |
| 94 | +echo "Go JSON Parser" |
| 95 | + |
| 96 | +go build -o scripts/json_parse scripts/json_parse.go |
| 97 | + |
| 98 | +echo "Nit/NitCC Parser" |
| 99 | + |
| 100 | +nitc --semi-global scripts/nitcc_parser.nit -o scripts/nitcc_parser |
| 101 | + |
| 102 | +echo "Nit/Ad-Hoc UTF-8 Parser, No Ropes" |
| 103 | + |
| 104 | +nitc --semi-global scripts/nit_adhoc_utf_noropes.nit -o scripts/nit_adhoc_utf_noropes |
| 105 | + |
| 106 | +echo "Nit/Ad-Hoc UTF-8 Parser, With Ropes" |
| 107 | + |
| 108 | +nitc --semi-global scripts/nit_adhoc_utf_ropes.nit -o scripts/nit_adhoc_utf_ropes |
| 109 | + |
| 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') |
| 112 | + |
| 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 |
| 119 | + done; |
| 120 | +done; |
| 121 | + |
| 122 | +rm scripts/nitcc_parser |
| 123 | +rm scripts/json_parse |
| 124 | +rm scripts/c_parser |
| 125 | +rm scripts/nit_adhoc_utf_noropes |
| 126 | +rm scripts/nit_adhoc_utf_ropes |
| 127 | + |
| 128 | +plot out/bench_json.gnu |
0 commit comments