Merge: nitunit: Use markdown2
[nit.git] / benchmarks / csv / csv_bench.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 mkdir -p inputs
32 nitc --semi-global scripts/csv_gen.nit -o scripts/csv_gen
33 echo "Generating 1000 lines documents"
34 ./scripts/csv_gen 10 1000 inputs/1000_l.csv
35 ./scripts/csv_gen 10 1000 inputs/1000_uni_l.csv --unicode
36 echo "Generating 10000 lines documents"
37 ./scripts/csv_gen 10 10000 inputs/10000_l.csv
38 ./scripts/csv_gen 10 10000 inputs/10000_uni_l.csv --unicode
39 echo "Generating 100000 lines documents"
40 ./scripts/csv_gen 10 100000 inputs/100000_l.csv
41 ./scripts/csv_gen 10 100000 inputs/100000_uni_l.csv --unicode
42 echo "Generating 1000000 lines documents"
43 ./scripts/csv_gen 10 1000000 inputs/1000000_l.csv
44 ./scripts/csv_gen 10 1000000 inputs/1000000_uni_l.csv --unicode
45 }
46
47 function usage()
48 {
49 echo "run_bench: ./csv_bench.sh [options]"
50 echo " -v: verbose mode"
51 echo " -n count: number of execution for each bar (default: $count)"
52 echo " -h: this help"
53 }
54
55 stop=false
56 fast=false
57 while [ "$stop" = false ]; do
58 case "$1" in
59 -v) verbose=true; shift;;
60 --fast) fast=true; shift;;
61 -h) usage; exit;;
62 -n) count="$2"; shift; shift;;
63 *) stop=true
64 esac
65 done
66
67 if [ -z "$fast" ]; then
68 init_repo
69 fi
70
71 mkdir -p out
72
73 echo "Compiling engines"
74
75 echo "Java Parser"
76
77 javac -cp './scripts/commons-csv-1.3.jar' scripts/JavaCSV.java
78
79 echo "Go parser"
80
81 go build -o scripts/go_csv scripts/go_csv.go
82
83 echo "Nit/Ad-Hoc Parser"
84
85 nitc --semi-global scripts/nit_csv.nit -o scripts/nit_csv
86
87 declare -a script_names=('Python 3 - Pandas' 'Python 2 - Pandas' 'Go' 'Nit' 'Python 3 - Standard' 'Python 2 - Standard' 'Java - Apache commons' 'Ruby')
88 declare -a script_cmds=('python3 scripts/python_csv.py' 'python2 scripts/python_csv.py' './scripts/go_csv' './scripts/nit_csv' 'python3 scripts/python_stdcsv.py' 'python2 scripts/python_stdcsv.py' "java -cp /usr/share/java/commons-csv.jar:. scripts.JavaCSV" 'ruby scripts/ruby_csv.rb')
89
90 for script in `seq 1 ${#script_cmds[@]}`; do
91 echo "Preparing res for ${script_names[$script - 1]}"
92 prepare_res "./out/${script_names[$script - 1]}.dat" "${script_names[$script - 1]}" "${script_names[$script - 1]}"
93 for file in inputs/*.csv; do
94 fname=`basename $file .csv`
95 bench_command $file "Benching file $file using ${script_cmds[$script - 1]} parser" ${script_cmds[$script - 1]} $file
96 done;
97 done;
98
99 rm scripts/nit_csv
100 rm scripts/JavaCSV.class
101 rm scripts/go_csv
102
103 plot out/bench_csv.gnu