OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
2 # Copyright 2016 the V8 project authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 ''' | |
6 (You'll need packages python-numpy and python-scipy.) | |
7 | |
8 This is a script for comparing v8-perf statistics for benchmarks run | |
9 on different versions of V8. Here's an example of how it can be used: | |
10 | |
11 ```bash | |
12 cd v8-perf/benchmarks/Octane2.1 | |
13 loop -100 ~/vanilla/v8/out/Release/d8 run-some.js -- code-load > vanilla.txt | |
14 loop -100 ~/v8/out/Release/d8 run-some.js -- code-load > modified.txt | |
15 ./v8-perf-statistics.py vanilla.txt modified.txt | |
16 ``` | |
17 | |
18 where I have defined `loop` to be: | |
19 | |
20 ```bash | |
21 function loop () { | |
22 limit=10 | |
23 case "$1" in | |
24 -*) | |
25 limit="${1#-}" | |
26 shift | |
27 esac | |
28 for ((i=1; i<=$limit; i++)); do | |
29 printf "%5d " $i | |
30 $* | |
31 done | |
32 } | |
33 ``` | |
34 | |
35 Multiple files can be supplied to the command line. The base file is | |
36 taken to be the first, but you can change this, e.g. | |
37 | |
38 ```bash | |
39 ./v8-perf-statistics.py -2 modified-1.txt vanilla.txt modified-2.txt | |
40 ``` | |
41 ''' | |
42 | |
43 import numpy, scipy, scipy.stats | |
44 from math import sqrt | |
45 | |
46 def statistics(data): | |
47 N = len(data) | |
48 average = numpy.average(data) | |
49 median = numpy.median(data) | |
50 low = numpy.min(data) | |
51 high= numpy.max(data) | |
52 # evaluate sample variance by setting delta degrees of freedom (ddof) to | |
53 # 1. The degree used in calculations is N - ddof | |
54 stdev = numpy.std(data, ddof=1) | |
55 # Get the endpoints of the range that contains 95% of the distribution | |
56 t_bounds = scipy.stats.t.interval(0.95, N-1) | |
57 # sum mean to the confidence interval | |
58 ci = [average + critval * stdev / sqrt(N) for critval in t_bounds] | |
59 return N, average, median, stdev, low, high, ci | |
60 | |
61 import re, sys | |
62 | |
63 F = [] | |
64 T = {} | |
65 base = 0 | |
66 | |
67 R = re.compile("\s*(\d+)?\s*([^:]*):\s*(\d+(.\d+)?)\s*") | |
68 | |
69 for arg in sys.argv[1:]: | |
70 if arg[0] == "-": | |
71 base = int(arg[1:]) - 1 | |
72 continue | |
73 F.append(arg) | |
74 with open(arg, "rt") as f: | |
75 S = {} | |
76 for line in f: | |
77 m = R.match(line) | |
78 assert m | |
Dan Ehrenberg
2016/03/18 18:40:37
When I use this script, I replace 'assert m' with
nickie
2016/03/21 16:09:37
Done. I'm fixing this in a better way.
| |
79 key = m.group(2) | |
80 value = int(m.group(3)) | |
81 if key not in S: S[key] = [] | |
82 S[key].append(value) | |
83 for key, values in S.items(): | |
84 if key not in T: T[key] = {} | |
85 T[key][arg] = statistics(values) | |
86 | |
87 base = F[base] | |
88 | |
89 for key in T: | |
90 print key | |
91 for arg in F: | |
92 def compare(i): | |
93 if arg == base: | |
94 return T[key][arg][i], "base" | |
95 diff = T[key][arg][i] - T[key][base][i] | |
96 perc = 100.0 * diff / T[key][base][i] | |
97 return T[key][arg][i], "{:+6.2f}".format(perc) | |
98 print " {}:".format(arg) | |
99 print " samples: {:5}".format(T[key][arg][0]) | |
100 print " average: {:8.2f} {}".format(*compare(1)) | |
101 print " median: {:8.2f} {}".format(*compare(2)) | |
102 print " stddev: {:8.2f} {}".format(*compare(3)) | |
103 print " minimum: {:5} {}".format(*compare(4)) | |
104 print " maximum: {:5} {}".format(*compare(5)) | |
105 print " CI 95%: {:8.2f} to {:8.2f}".format(*T[key][arg][6]) | |
OLD | NEW |