js/src/tests/compare_bench.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env python2.4
michael@0 2 """usage: %progname candidate_path baseline_path
michael@0 3 """
michael@0 4
michael@0 5 import json
michael@0 6 import optparse
michael@0 7 from contextlib import nested
michael@0 8 from operator import itemgetter
michael@0 9
michael@0 10
michael@0 11 def avg(seq):
michael@0 12 return sum(seq) / len(seq)
michael@0 13
michael@0 14
michael@0 15 def compare(current, baseline):
michael@0 16 percent_speedups = []
michael@0 17 for key, current_result in current.iteritems():
michael@0 18 try:
michael@0 19 baseline_result = baseline[key]
michael@0 20 except KeyError:
michael@0 21 print key, 'missing from baseline'
michael@0 22 continue
michael@0 23 val_getter = itemgetter('average_ms', 'stddev_ms')
michael@0 24 base_avg, base_stddev = val_getter(baseline_result)
michael@0 25 current_avg, current_stddev = val_getter(current_result)
michael@0 26 t_best, t_worst = current_avg - current_stddev, current_avg + current_stddev
michael@0 27 base_t_best, base_t_worst = base_avg - base_stddev, base_avg + base_stddev
michael@0 28 fmt = '%30s: %s'
michael@0 29 if t_worst < base_t_best: # Worst takes less time (better) than baseline's best.
michael@0 30 speedup = -((t_worst - base_t_best) / base_t_best) * 100
michael@0 31 result = 'faster: %6.2fms < baseline %6.2fms (%+6.2f%%)' % \
michael@0 32 (t_worst, base_t_best, speedup)
michael@0 33 percent_speedups.append(speedup)
michael@0 34 elif t_best > base_t_worst: # Best takes more time (worse) than baseline's worst.
michael@0 35 slowdown = -((t_best - base_t_worst) / base_t_worst) * 100
michael@0 36 result = 'SLOWER: %6.2fms > baseline %6.2fms (%+6.2f%%) ' % \
michael@0 37 (t_best, base_t_worst, slowdown)
michael@0 38 percent_speedups.append(slowdown)
michael@0 39 else:
michael@0 40 result = 'Meh.'
michael@0 41 print '%30s: %s' % (key, result)
michael@0 42 if percent_speedups:
michael@0 43 print 'Average speedup: %.2f%%' % avg(percent_speedups)
michael@0 44
michael@0 45
michael@0 46 def compare_immediate(current_map, baseline_path):
michael@0 47 baseline_file = open(baseline_path)
michael@0 48 baseline_map = json.load(baseline_file)
michael@0 49 baseline_file.close()
michael@0 50 compare(current_map, baseline_map)
michael@0 51
michael@0 52
michael@0 53 def main(candidate_path, baseline_path):
michael@0 54 candidate_file, baseline_file = open(candidate_path), open(baseline_path)
michael@0 55 candidate = json.load(candidate_file)
michael@0 56 baseline = json.load(baseline_file)
michael@0 57 compare(candidate, baseline)
michael@0 58 candidate_file.close()
michael@0 59 baseline_file.close()
michael@0 60
michael@0 61
michael@0 62 if __name__ == '__main__':
michael@0 63 parser = optparse.OptionParser(usage=__doc__.strip())
michael@0 64 options, args = parser.parse_args()
michael@0 65 try:
michael@0 66 candidate_path = args.pop(0)
michael@0 67 except IndexError:
michael@0 68 parser.error('A JSON filepath to compare against baseline is required')
michael@0 69 try:
michael@0 70 baseline_path = args.pop(0)
michael@0 71 except IndexError:
michael@0 72 parser.error('A JSON filepath for baseline is required')
michael@0 73 main(candidate_path, baseline_path)

mercurial