benches: moved bench in its own directory at project root
[nit.git] / benchmarks / bench_plot.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 # This shell script generate gnuplot results
17
18 # perl function to compute min/max/avg.
19 # used by bench_command
20 #
21 # $1: file
22 # return: first min max avg label
23 function compute_stats()
24 {
25 file="$1"
26 # Compute statistics
27 perl - "$file" <<'END'
28 @lines = ();
29 $first = undef;
30 chomp($label = <>);
31 while(<>) {
32 chomp;
33 if (/^\d/) {
34 if (defined $first) {
35 push @lines, $_;
36 } else {
37 $first = $_;
38 }
39 }
40 }
41 $len = scalar @lines;
42 if ($len) {
43 @lines = sort {$a <=> $b} @lines;
44 $min = $lines[0];
45 $max = $lines[$#lines];
46 $avg = 0;
47 for $i (@lines) { $avg += $i; }
48 $avg = $avg / $len;
49 print "${first} ${min} ${max} ${avg} \"${label}\"\n";
50 } else {
51 print "${first} ${first} ${first} ${first} \"${label}\"\n";
52 }
53 END
54 }
55
56 # Create a new $res to be used in the next plot
57 #
58 # $1 = resfile
59 # $2 = title
60 # $3 = description
61 function prepare_res()
62 {
63 echo
64 echo "# [$2] $3 #"
65 res=$1
66 if [ "$plots" = "" ]; then
67 plots="plot '$1' using 4:2:3:xticlabels(5) ti '$2';"
68 else
69 plots="$plots replot '$1' using 4:2:3 ti '$2';"
70 fi
71 if [ "$dry_run" = "true" ]; then return; fi
72 echo "# [$2] $3 ; count=$count" > "$res"
73 echo "# first min max avg title" >> "$res"
74 }
75
76 # Plot the last $res as an histogram
77 # $1: plot file (eg toto.gnu)
78 function plot()
79 {
80 cat >"$1" <<END
81 set auto x;
82 set yrange [0:];
83 set style data histogram;
84 set style histogram cluster gap 2;
85 set style histogram errorbars linewidth 1;
86 set style fill solid 0.3 border -1;
87 set bars front;
88 set boxwidth 0.9;
89 set xtic nomirror rotate by -45 scale 0 font ',8';
90 set title "$1 ; avg. on $count-1 runs"
91 set ylabel "time (s)"
92 $plots
93 END
94 echo "# gnuplot -p $1"
95 gnuplot -p "$1"
96 plots=
97 }
98
99 ## GLOBAL VARIABLES ##
100
101 # The current $res (set by prepare_res, used by bench_command)
102 res=
103
104 # The current stuff to plot (set by prepare_res, used by plot)
105 plots=
106