blob: fd30cc8c5d26bfb0f211a5793813741fa266510a [file] [log] [blame]
keith_miller@apple.coma8f138f2016-05-24 19:00:51 +00001#!/usr/bin/env python
2# Copyright (C) 2011, 2012 Purdue University
3# Written by Gregor Richards
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8#
9# 1. Redistributions of source code must retain the above copyright notice,
10# this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright notice,
12# this list of conditions and the following disclaimer in the documentation
13# and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26
27import math
28import os
29import re
30import sys
31
32benchmarks = ["amazon/chrome", "amazon/firefox", "amazon/safari",
33 "facebook/chrome", "facebook/firefox", "facebook/safari",
34 "google/chrome", "google/firefox", "google/safari",
35 "twitter/chrome", "twitter/firefox", "twitter/safari",
36 "yahoo/chrome", "yahoo/firefox", "yahoo/safari"]
37modes = {
38 "*": ["urem"],
39 "amazon/firefox": ["urm"],
40 "google/firefox": ["uem"]
41}
42runcount = 25
43keepruns = 20
44
45keepfrom = runcount - keepruns
46
47if len(sys.argv) != 2:
annulen@yandex.ru70acd2e2017-12-08 21:56:09 +000048 print("Use: python harness.py <JS executable>")
keith_miller@apple.coma8f138f2016-05-24 19:00:51 +000049 exit(1)
50js = sys.argv[1]
51
52# standard t-distribution for normally distributed samples
53tDistribution = [0, 0, 12.71, 4.30, 3.18, 2.78, 2.57, 2.45, 2.36, 2.31, 2.26,
542.23, 2.20, 2.18, 2.16, 2.14, 2.13, 2.12, 2.11, 2.10, 2.09, 2.09, 2.08, 2.07,
552.07, 2.06, 2.06, 2.06, 2.05, 2.05, 2.05, 2.04, 2.04, 2.04, 2.03, 2.03, 2.03,
562.03, 2.03, 2.02, 2.02, 2.02, 2.02, 2.02, 2.02, 2.02, 2.01, 2.01, 2.01, 2.01,
572.01, 2.01, 2.01, 2.01, 2.01, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00,
582.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99,
591.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99,
601.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.99, 1.98, 1.98, 1.98, 1.98, 1.98,
611.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98,
621.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98,
631.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98,
641.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.98,
651.98, 1.98, 1.98, 1.98, 1.98, 1.98, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
661.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
671.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
681.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
691.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
701.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
711.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
721.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
731.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
741.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
751.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
761.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
771.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
781.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
791.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
801.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
811.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
821.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
831.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
841.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
851.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
861.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
871.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
881.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97,
891.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.97, 1.96]
90
91def tDist(n):
92 if (n >= len(tDistribution)):
93 return tDistribution[-1]
94 return tDistribution[n]
95
96results = {}
97
98for benchmark in benchmarks:
99 results[benchmark] = {}
100
101 bmodes = modes["*"]
102 if benchmark in modes:
103 bmodes = modes[benchmark]
104
105 for mode in bmodes:
106 results[benchmark][mode] = []
107
108 for runno in range(runcount):
109 # Now run it and get the results
110 print(benchmark + " " + mode + " " + str(runno))
111 res = os.popen(js + " " + benchmark + "/" + mode + ".js").read()
112 time = float(re.match("Time: ([0-9]*)ms", res).group(1))
113
114 if runno >= keepfrom:
115 results[benchmark][mode].append(time)
116
117# Collect the totals
118sresults = {}
119totals = {
120 "mean": 1,
121 "stddev": 1,
122 "sem": 1,
123 "ci": 1,
124 "runs": 0
125}
126
127for benchmark in benchmarks:
128 sresults[benchmark] = {}
129
130 bmodes = modes["*"]
131 if benchmark in modes:
132 bmodes = modes[benchmark]
133
134 for mode in bmodes:
135 sresults[benchmark][mode] = sresult = {}
136 result = results[benchmark][mode]
137 totals["runs"] = totals["runs"] + 1
138
139 sresult["mode"] = mode
140
141 mean = sresult["mean"] = sum(result) / len(result)
142 stddev = sresult["stddev"] = math.sqrt(
143 sum(
144 map(lambda e: math.pow(e - mean, 2), result)
145 ) / (len(result) - 1)
146 )
147
148 sm = sresult["sm"] = stddev / mean
149 sem = sresult["sem"] = stddev / math.sqrt(len(result))
150 semm = sresult["semm"] = sem / mean
151 ci = sresult["ci"] = tDist(len(result)) * sem
152 cim = sresult["cim"] = ci / mean
153
154 totals["mean"] *= mean
155 totals["stddev"] *= stddev
156 totals["sem"] *= sem
157 totals["ci"] *= ci
158
159power = 1 / totals["runs"]
160totals["mean"] = math.pow(totals["mean"], power)
161totals["stddev"] = math.pow(totals["stddev"], power)
162totals["sm"] = totals["stddev"] / totals["mean"]
163totals["sem"] = math.pow(totals["sem"], power)
164totals["semm"] = totals["sem"] / totals["mean"]
165totals["ci"] = math.pow(totals["ci"], power)
166totals["cim"] = totals["ci"] / totals["mean"]
167
168totals["sm"] *= 100
169totals["semm"] *= 100
170totals["cim"] *= 100
171
annulen@yandex.ru70acd2e2017-12-08 21:56:09 +0000172print("Final results:")
173print(u" %(mean)fms \u00b1 %(cim)f%% (lower is better)" % totals)
174print(" Standard deviation = %(sm)f%% of mean" % totals)
175print(" Standard error = %(semm)f%% of mean" % totals)
176print(" %(runs)d runs" % {"runs": runcount})
177print("")
keith_miller@apple.coma8f138f2016-05-24 19:00:51 +0000178
annulen@yandex.ru70acd2e2017-12-08 21:56:09 +0000179print("Result breakdown:")
keith_miller@apple.coma8f138f2016-05-24 19:00:51 +0000180for benchmark in benchmarks:
annulen@yandex.ru70acd2e2017-12-08 21:56:09 +0000181 print(" %(benchmark)s:" % {"benchmark": benchmark})
keith_miller@apple.coma8f138f2016-05-24 19:00:51 +0000182
183 bmodes = modes["*"]
184 if benchmark in modes:
185 bmodes = modes[benchmark]
186
187 for mode in bmodes:
annulen@yandex.ru70acd2e2017-12-08 21:56:09 +0000188 print(u" %(mode)s: %(mean)fms \u00b1 %(cim)f%% (stddev=%(sm)f%%, stderr=%(semm)f%%)" % sresults[benchmark][mode])
189print("")
keith_miller@apple.coma8f138f2016-05-24 19:00:51 +0000190
annulen@yandex.ru70acd2e2017-12-08 21:56:09 +0000191print("Raw results:")
keith_miller@apple.coma8f138f2016-05-24 19:00:51 +0000192for benchmark in benchmarks:
annulen@yandex.ru70acd2e2017-12-08 21:56:09 +0000193 print(" %(benchmark)s:" % {"benchmark": benchmark})
keith_miller@apple.coma8f138f2016-05-24 19:00:51 +0000194
195 bmodes = modes["*"]
196 if benchmark in modes:
197 bmodes = modes[benchmark]
198
199 for mode in bmodes:
annulen@yandex.ru70acd2e2017-12-08 21:56:09 +0000200 print(" %(mode)s: %(results)s" % {
keith_miller@apple.coma8f138f2016-05-24 19:00:51 +0000201 "mode": mode,
202 "results": results[benchmark][mode]
annulen@yandex.ru70acd2e2017-12-08 21:56:09 +0000203 })