forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompare-results
executable file
·815 lines (662 loc) · 29.8 KB
/
compare-results
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
#!/usr/bin/env python3 -u
# Copyright (C) 2019 Apple Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of Apple Inc. ("Apple") nor the names of
# its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import collections
import sys
import argparse
import json
import itertools
from webkitpy.benchmark_runner.benchmark_results import BenchmarkResults
from webkitpy.benchmark_runner.benchmark_json_merge import mergeJSONs
try:
from scipy import stats
except:
print("ERROR: scipy package is not installed. Run `pip install scipy`")
sys.exit(1)
try:
import numpy
except:
print("ERROR: numpy package is not installed. Run `pip install numpy`")
sys.exit(1)
def readJSONFile(path):
with open(path, 'r') as contents:
result = json.loads(contents.read())
if 'debugOutput' in result:
del result['debugOutput']
return result
Speedometer3 = "Speedometer3"
Speedometer2 = "Speedometer2"
JetStream3 = "JetStream3"
JetStream2 = "JetStream2"
PLT5 = "PLT5"
CompetitivePLT = "CompetitivePLT"
PLUM3 = "PLUM3"
MotionMark = "MotionMark"
MotionMark1_1 = "MotionMark-1.1"
MotionMark1_1_1 = "MotionMark-1.1.1"
MotionMark1_2 = "MotionMark-1.2"
MotionMark1_3 = "MotionMark-1.3"
RAMification = "RAMification"
unitMarker = "__unit__"
def speedometer3Breakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "ms"
for test in breakdown._results["Speedometer-3"]["tests"].keys():
result[test] = breakdown._results["Speedometer-3"]["tests"][test]["metrics"]["Time"]["Total"]["current"]
return result
def speedometer3BreakdownSyncAsync(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "ms"
for test in breakdown._results["Speedometer-3"]["tests"].keys():
syncTime = None
asyncTime = None
for value in breakdown._results["Speedometer-3"]["tests"][test]["tests"].values():
syncArray = value["tests"]["Sync"]["metrics"]["Time"][None]["current"]
asyncArray = value["tests"]["Async"]["metrics"]["Time"][None]["current"]
if not syncTime:
syncTime = syncArray
asyncTime = asyncArray
else:
syncTime = [x + y for x, y in zip(syncTime, syncArray)]
asyncTime = [x + y for x, y in zip(asyncTime, asyncArray)]
result[test + "-sync"] = syncTime
result[test + "-async"] = asyncTime
return result
def speedometer2Breakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "ms"
for test in breakdown._results["Speedometer-2"]["tests"].keys():
result[test] = breakdown._results["Speedometer-2"]["tests"][test]["metrics"]["Time"]["Total"]["current"]
return result
def speedometer2BreakdownSyncAsync(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "ms"
for test in breakdown._results["Speedometer-2"]["tests"].keys():
syncTime = None
asyncTime = None
for value in breakdown._results["Speedometer-2"]["tests"][test]["tests"].values():
syncArray = value["tests"]["Sync"]["metrics"]["Time"][None]["current"]
asyncArray = value["tests"]["Async"]["metrics"]["Time"][None]["current"]
if not syncTime:
syncTime = syncArray
asyncTime = asyncArray
else:
syncTime = [x + y for x, y in zip(syncTime, syncArray)]
asyncTime = [x + y for x, y in zip(asyncTime, asyncArray)]
result[test + "-sync"] = syncTime
result[test + "-async"] = asyncTime
return result
def jetStream2Breakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "pts"
for test in breakdown._results["JetStream2.0"]["tests"].keys():
result[test] = breakdown._results["JetStream2.0"]["tests"][test]["metrics"]["Score"][None]["current"]
return result
def detailedJetStream2Breakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "ms"
for test in breakdown._results["JetStream2.0"]["tests"].keys():
for subtest in breakdown._results["JetStream2.0"]["tests"][test]["tests"]:
result[test + "-" + subtest] = breakdown._results["JetStream2.0"]["tests"][test]["tests"][subtest]["metrics"]["Time"][None]["current"]
return result
def categoryJetStream2Breakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "ms"
for test in breakdown._results["JetStream2.0"]["tests"].keys():
for category in breakdown._results["JetStream2.0"]["tests"][test]["tests"]:
if not category in result:
result[category] = []
result[category] += breakdown._results["JetStream2.0"]["tests"][test]["tests"][category]["metrics"]["Time"][None]["current"]
return result
def jetStream3Breakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "pts"
for test in breakdown._results["JetStream3.0"]["tests"].keys():
result[test] = breakdown._results["JetStream3.0"]["tests"][test]["metrics"]["Score"][None]["current"]
return result
def detailedJetStream3Breakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "ms"
for test in breakdown._results["JetStream3.0"]["tests"].keys():
for subtest in breakdown._results["JetStream3.0"]["tests"][test]["tests"]:
result[test + "-" + subtest] = breakdown._results["JetStream3.0"]["tests"][test]["tests"][subtest]["metrics"]["Time"][None]["current"]
return result
def categoryJetStream3Breakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "ms"
for test in breakdown._results["JetStream3.0"]["tests"].keys():
for category in breakdown._results["JetStream3.0"]["tests"][test]["tests"]:
if not category in result:
result[category] = []
result[category] += breakdown._results["JetStream3.0"]["tests"][test]["tests"][category]["metrics"]["Time"][None]["current"]
return result
def motionMarkBreakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "pts"
if detectMotionMark(jsonObject):
name = "MotionMark"
elif detectMotionMark1_1(jsonObject):
name = "MotionMark-1.1"
elif detectMotionMark1_1_1(jsonObject):
name = "MotionMark-1.1.1"
elif detectMotionMark1_2(jsonObject):
name = "MotionMark-1.2"
elif detectMotionMark1_3(jsonObject):
name = "MotionMark-1.3"
for test in breakdown._results[name]["tests"].keys():
result[test] = breakdown._results[name]["tests"][test]["metrics"]["Score"][None]["current"]
return result
def plt5Breakdown(jsonObject):
nameMapping = {}
for mappings in jsonObject["urls"]:
for key in mappings.keys():
nameMapping[key] = mappings[key]
result = {}
result[unitMarker] = "ms"
for test in jsonObject["iterations"][0]["warm"].keys():
if test == "Geometric":
continue
result["warm--" + nameMapping[test]] = []
result["cold--" + nameMapping[test]] = []
for payload in jsonObject["iterations"]:
warmTests = payload["warm"]
coldTests = payload["cold"]
for test in warmTests.keys():
if test == "Geometric":
continue
result["warm--" + nameMapping[test]].append(warmTests[test]["Geometric"])
result["cold--" + nameMapping[test]].append(coldTests[test]["Geometric"])
return result
def competitivePLTBreakdown(jsonObject):
result = collections.defaultdict(list)
result[unitMarker] = "sec"
safari_results = jsonObject.get('Safari', {})
cold_results = safari_results.get('cold', {})
warm_results = safari_results.get('warm', {})
cold_link_results = cold_results.get('add-and-click-link', {})
warm_link_results = warm_results.get('add-and-click-link', {})
for site_to_times in cold_link_results.values():
for site, times in site_to_times.items():
result["cold--fmp--" + site].append(times['first_meaningful_paint'])
result["cold--load-end--" + site].append(times['load_end'])
for site_to_times in warm_link_results.values():
for site, times in site_to_times.items():
result["warm--fmp--" + site].append(times['first_meaningful_paint'])
result["warm--load-end--" + site].append(times['load_end'])
return result
def plum3Breakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "B"
for test in breakdown._results["PLUM3-PhysFootprint"]["tests"].keys():
result[test] = breakdown._results["PLUM3-PhysFootprint"]["tests"][test]["metrics"]["Allocations"]["Geometric"]["current"]
return result
def ramificationBreakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "B"
for test in breakdown._results["RAMification"]["tests"].keys():
result[test] = breakdown._results["RAMification"]["tests"][test]["metrics"]["Allocations"]["Geometric"]["current"]
return result
def detailedRAMificationBreakdown(jsonObject):
breakdown = BenchmarkResults(jsonObject)
result = {}
result[unitMarker] = "B"
for test in breakdown._results["RAMification"]["tests"].keys():
for subtest in breakdown._results["RAMification"]["tests"][test]["tests"]:
result[test + "-" + subtest] = breakdown._results["RAMification"]["tests"][test]["tests"][subtest]["metrics"]["Allocations"]["Geometric"]["current"]
return result
def displayStr(value):
return "{:.6f}".format(float(value))
def computeMultipleHypothesesSignificance(a, b):
# This is using the Benjamini-Hochberg procedure based on False Discovery Rate
# for computing signifcance in multiple hypothesis testing
# Read more here:
# - https://en.wikipedia.org/wiki/False_discovery_rate
# - https://www.stat.berkeley.edu/~mgoldman/Section0402.pdf
# This is best used for independent variables. We know subtests aren't
# fully independent, this it's a reasonable approximation.
# We use this instead of Bonferroni because we control for almost the same
# false positive error rate (marking as signficant when it's not), but with a much
# lower false negative error rate (not marking something as signficant when it is).
sortedPValues = []
reversePValueMap = {}
for key in a.keys():
if key == unitMarker:
continue
(tStatistic, pValue) = stats.ttest_ind(a[key], b[key], equal_var=False)
sortedPValues.append(pValue)
if pValue not in reversePValueMap:
reversePValueMap[pValue] = []
reversePValueMap[pValue].append(key)
sortedPValues.sort()
assert sortedPValues[0] <= sortedPValues[-1]
isSignificant = False
result = {}
rank = float(len(sortedPValues))
for pValue in reversed(sortedPValues):
assert rank >= 1.0
threshold = (rank * .05) / float(len(sortedPValues))
if pValue <= threshold:
isSignificant = True
assert len(reversePValueMap[pValue]) > 0
for test in reversePValueMap[pValue]:
result[test] = isSignificant
rank = rank - 1.0
return result
def dumpBreakdowns(a, b, sort_flag=False):
nameLength = len("subtest")
aLength = len(a[unitMarker])
bLength = len(a[unitMarker])
ratioLength = len("b / a")
pValueHeader = "pValue (significance using False Discovery Rate)"
pLength = len(pValueHeader)
isSignificant = computeMultipleHypothesesSignificance(a, b)
for key in a.keys():
if key == unitMarker:
continue
nameLength = max(nameLength, len(key))
aLength = max(aLength, len(displayStr(numpy.mean(a[key]))))
bLength = max(bLength, len(displayStr(numpy.mean(b[key]))))
ratioLength = max(ratioLength, len(displayStr(numpy.mean(b[key]) / numpy.mean(a[key]))))
(tStatistic, pValue) = stats.ttest_ind(a[key], b[key], equal_var=False)
significantStr = ""
if isSignificant[key]:
significantStr = " (significant)"
pLength = max(pLength, len(displayStr(pValue)) + len(significantStr))
aLength += 2
bLength += 2
nameLength += 2
ratioLength += 2
pLength += 2
strings = []
strings.append("|{key:^{nameLength}}|{aScore:^{aLength}} |{bScore:^{bLength}} |{compare:^{ratioLength}}|{pMarker:^{pLength}}|".format(key="subtest", aScore=a[unitMarker], bScore=b[unitMarker], nameLength=nameLength, aLength=aLength, bLength=bLength , compare="b / a", ratioLength=ratioLength, pMarker=pValueHeader, pLength=pLength))
keys = [k for k in a.keys() if k != unitMarker]
if sort_flag:
keys.sort(key=lambda k: numpy.mean(b[k]) / numpy.mean(a[k]))
else:
keys.sort()
for key in keys:
aScore = numpy.mean(a[key])
bScore = numpy.mean(b[key])
(tStatistic, pValue) = stats.ttest_ind(a[key], b[key], equal_var=False)
significantStr = ""
if isSignificant[key]:
significantStr = " (significant)"
strings.append("| {key:{nameLength}}|{aScore:{aLength}} |{bScore:{bLength}} |{compare:{ratioLength}}| {pValue:<{pLength}}|".format(key=key, aScore=displayStr(aScore), bScore=displayStr(bScore), nameLength=nameLength - 1, aLength=aLength, bLength=bLength, ratioLength=ratioLength, compare=displayStr(bScore / aScore), pValue = displayStr(pValue) + significantStr, pLength=pLength - 1))
maxLen = 0
for s in strings:
maxLen = max(maxLen, len(s))
verticalSeparator = "-" * maxLen
strings.insert(0, verticalSeparator)
strings.insert(2, verticalSeparator)
strings.append(verticalSeparator)
print("\n")
for s in strings:
print(s)
print("\n")
def writeCSV(a, b, fileName, sort_flag):
strings = []
result = ""
result += "test_name, {}, {}, b_divided_by_a, pValue, is_significant_using_False_Discovery_Rate\n".format("a_in_" + a[unitMarker], "b_in_" + b[unitMarker])
isSignificant = computeMultipleHypothesesSignificance(a, b)
keys = [k for k in a.keys() if k != unitMarker]
if sort_flag:
keys.sort(key=lambda k: numpy.mean(b[k]) / numpy.mean(a[k]))
else:
keys.sort()
for key in keys:
aScore = numpy.mean(a[key])
bScore = numpy.mean(b[key])
(tStatistic, pValue) = stats.ttest_ind(a[key], b[key], equal_var=False)
significantStr = "No"
if isSignificant[key]:
significantStr = "Yes"
result += "{},{},{},{},{},{}\n".format(key, displayStr(aScore), displayStr(bScore), displayStr(bScore / aScore), displayStr(pValue), significantStr)
f = open(fileName, "w")
f.write(result)
f.close()
def detectJetStream3(payload):
return "JetStream3.0" in payload
def detectJetStream2(payload):
return "JetStream2.0" in payload
def JetStream2Results(payload):
assert detectJetStream2(payload)
js = payload["JetStream2.0"]
iterations = 0
if "gaussian-blur" in js["tests"]:
iterations = len(js["tests"]["gaussian-blur"]["metrics"]["Score"]["current"])
else:
obj = js["tests"]
first_key = list(obj.keys())[0]
iterations = len(obj[first_key]["metrics"]["Score"]["current"])
results = []
for i in range(iterations):
scores = []
for test in js["tests"].keys():
scores.append(js["tests"][test]["metrics"]["Score"]["current"][i])
geomean = stats.gmean(scores)
results.append(geomean)
return results
def JetStream3Results(payload):
assert detectJetStream3(payload)
js = payload["JetStream3.0"]
iterations = 0
if "gaussian-blur" in js["tests"]:
iterations = len(js["tests"]["gaussian-blur"]["metrics"]["Score"]["current"])
else:
obj = js["tests"]
first_key = list(obj.keys())[0]
iterations = len(obj[first_key]["metrics"]["Score"]["current"])
results = []
for i in range(iterations):
scores = []
for test in js["tests"].keys():
scores.append(js["tests"][test]["metrics"]["Score"]["current"][i])
geomean = stats.gmean(scores)
results.append(geomean)
return results
def detectSpeedometer2(payload):
return "Speedometer-2" in payload
def detectSpeedometer3(payload):
return "Speedometer-3" in payload
def Speedometer2Results(payload):
assert detectSpeedometer2(payload)
results = []
for arr in payload["Speedometer-2"]["metrics"]["Score"]["current"]:
results.append(numpy.mean(arr))
return results
def Speedometer3Results(payload):
assert detectSpeedometer3(payload)
results = []
for arr in payload["Speedometer-3"]["metrics"]["Score"]["current"]:
results.append(numpy.mean(arr))
return results
def detectPLT5(payload):
if "iterations" not in payload:
return False
iterations = payload["iterations"]
if not isinstance(iterations, list):
return False
if not len(iterations):
return False
if "cold" not in iterations[0]:
return False
if "warm" not in iterations[0]:
return False
if "Geometric" not in iterations[0]:
return False
return True
def PLT5Results(payload):
assert detectPLT5(payload)
results = []
for obj in payload["iterations"]:
results.append(obj["Geometric"])
return results
def detectCompetitivePLT(payload):
return 'add-and-click-link' in payload.get('Safari', {}).get('cold', {})
def CompetitivePLTResults(payload):
def calculate_time_for_run(run):
# We geomean all FMP and load_end times together to produce a result for the run.
fmp_vals = [obj['first_meaningful_paint'] for obj in run.values()]
load_end_vals = [obj['load_end'] for obj in run.values()]
return stats.gmean(fmp_vals + load_end_vals)
safari_results = payload.get('Safari', {})
cold_results = safari_results.get('cold', {})
warm_results = safari_results.get('warm', {})
cold_link_results = cold_results.get('add-and-click-link', {})
warm_link_results = warm_results.get('add-and-click-link', {})
cold_times = [calculate_time_for_run(run) for run in cold_link_results.values()]
warm_times = [calculate_time_for_run(run) for run in warm_link_results.values()]
return [stats.gmean((cold_time, warm_time)) for cold_time, warm_time in zip(cold_times, warm_times)]
def detectPLUM3(payload):
return "PLUM3-PhysFootprint" in payload
def PLUM3Results(payload):
assert detectPLUM3(payload)
breakdown = BenchmarkResults(payload)
return breakdown._results["PLUM3-PhysFootprint"]["metrics"]["Allocations"]["Arithmetic"]["current"]
def detectMotionMark(payload):
return "MotionMark" in payload
def detectMotionMark1_1(payload):
return "MotionMark-1.1" in payload
def detectMotionMark1_1_1(payload):
return "MotionMark-1.1.1" in payload
def detectMotionMark1_2(payload):
return "MotionMark-1.2" in payload
def detectMotionMark1_3(payload):
return "MotionMark-1.3" in payload
def motionMarkResults(payload):
assert any(validMotionMarkDetector(payload) for validMotionMarkDetector in [detectMotionMark, detectMotionMark1_1, detectMotionMark1_1_1, detectMotionMark1_2, detectMotionMark1_3])
if detectMotionMark(payload):
payload = payload["MotionMark"]
elif detectMotionMark1_1(payload):
payload = payload["MotionMark-1.1"]
elif detectMotionMark1_1_1(payload):
payload = payload["MotionMark-1.1.1"]
elif detectMotionMark1_2(payload):
payload = payload["MotionMark-1.2"]
else:
payload = payload["MotionMark-1.3"]
testNames = list(payload["tests"].keys())
numTests = len(payload["tests"][testNames[0]]["metrics"]["Score"]["current"])
results = []
for i in range(numTests):
scores = []
for test in testNames:
scores.append(payload["tests"][test]["metrics"]["Score"]["current"][i])
results.append(stats.gmean(scores))
return results
def detectRAMification(payload):
return "RAMification" in payload
def RAMificationResults(payload):
assert detectRAMification(payload)
breakdown = BenchmarkResults(payload)
return breakdown._results["RAMification"]["metrics"]["Allocations"][None]["current"]
def detectBenchmark(payload):
if detectJetStream3(payload):
return JetStream3
if detectJetStream2(payload):
return JetStream2
if detectSpeedometer2(payload):
return Speedometer2
if detectSpeedometer3(payload):
return Speedometer3
if detectPLT5(payload):
return PLT5
if detectCompetitivePLT(payload):
return CompetitivePLT
if detectPLUM3(payload):
return PLUM3
if detectMotionMark(payload):
return MotionMark
if detectMotionMark1_1(payload):
return MotionMark1_1
if detectMotionMark1_1_1(payload):
return MotionMark1_1
if detectMotionMark1_2(payload):
return MotionMark1_2
if detectMotionMark1_3(payload):
return MotionMark1_3
if detectRAMification(payload):
return RAMification
return None
def biggerIsBetter(benchmarkType):
if benchmarkType in [JetStream2, JetStream3, Speedometer2, Speedometer3, MotionMark, MotionMark1_1, MotionMark1_1_1, MotionMark1_2, MotionMark1_3]:
return True
elif benchmarkType in [PLT5, CompetitivePLT, PLUM3, RAMification]:
return False
else:
raise Exception('An unknown benchmark type was passed into biggerIsBetter: {}. It should not be possible to hit this.'.format(benchmarkType))
def ttest(benchmarkType, a, b):
# We use two-tailed Welch's
(tStatistic, pValue) = stats.ttest_ind(a, b, equal_var=False)
aMean = numpy.mean(a)
bMean = numpy.mean(b)
print("a mean = {:.5f}".format(aMean))
print("b mean = {:.5f}".format(bMean))
print("pValue = {:.10f}".format(pValue))
if biggerIsBetter(benchmarkType):
print("(Bigger means are better.)")
if aMean > bMean:
print("{:.3f} times worse".format((aMean / bMean)))
else:
print("{:.3f} times better".format((bMean / aMean)))
else:
print("(Smaller means are better.)")
if aMean > bMean:
print("{:.3f} times better".format((aMean / bMean)))
else:
print("{:.3f} times worse".format((bMean / aMean)))
if pValue <= 0.05:
print("Results ARE significant")
else:
print("Results ARE NOT significant")
def getOptions():
parser = argparse.ArgumentParser(description="Compare two WebKit benchmark results. Pass in at least two JSON result files to compare them. This script prints the pValue along with the magnitude of the change. If more than one JSON is passed as a/b they will be merged when computing the breakdown.")
parser.add_argument("-a",
type=str,
required=True,
nargs='+',
action="append",
help="a JSONs of a/b. Path to JSON results file. Takes multiple values and can be passed multiple times.")
parser.add_argument("-b",
type=str,
required=True,
nargs='+',
action="append",
help="b JSONs of a/b. Path to JSON results file. Takes multiple values and can be passed multiple times.")
parser.add_argument("--csv",
type=str,
required=False,
help="Path to write a csv file containing subtest breakdown.")
parser.add_argument("--breakdown", action="store_true",
default=False, help="Print a per subtest breakdown.")
parser.add_argument("--detailed-breakdown", action="store_true",
default=False, help="Print a detailed breakdown per subtest.")
parser.add_argument("--category-breakdown", action="store_true",
default=False, help="Print a breakdown per category. (e.g. startup, average, worst)")
parser.add_argument("--sort", action="store_true",
default=False, help="Sort the tests/sub-tests by b / a.")
return parser.parse_known_args()[0]
def main():
args = getOptions()
# Flatten the list of lists of JSON files.
a = itertools.chain.from_iterable(args.a)
b = itertools.chain.from_iterable(args.b)
a = mergeJSONs(list(map(readJSONFile, a)))
b = mergeJSONs(list(map(readJSONFile, b)))
typeA = detectBenchmark(a)
typeB = detectBenchmark(b)
if typeA != typeB:
print("-a and -b are not the same benchmark. a={} b={}".format(typeA, typeB))
sys.exit(1)
if not (typeA and typeB):
print("Unknown benchmark type. a={} b={}".format(typeA, typeB))
sys.exit(1)
if typeA == JetStream2:
if args.detailed_breakdown:
dumpBreakdowns(detailedJetStream2Breakdown(a), detailedJetStream2Breakdown(b), args.sort)
if args.category_breakdown:
dumpBreakdowns(categoryJetStream2Breakdown(a), categoryJetStream2Breakdown(b), args.sort)
if args.breakdown:
dumpBreakdowns(jetStream2Breakdown(a), jetStream2Breakdown(b), args.sort)
ttest(typeA, JetStream2Results(a), JetStream2Results(b))
if args.csv:
writeCSV(jetStream2Breakdown(a), jetStream2Breakdown(b), args.csv, args.sort)
elif typeA == JetStream3:
if args.detailed_breakdown:
dumpBreakdowns(detailedJetStream3Breakdown(a), detailedJetStream3Breakdown(b), args.sort)
if args.category_breakdown:
dumpBreakdowns(categoryJetStream3Breakdown(a), categoryJetStream3Breakdown(b), args.sort)
if args.breakdown:
dumpBreakdowns(jetStream3Breakdown(a), jetStream3Breakdown(b), args.sort)
ttest(typeA, JetStream3Results(a), JetStream3Results(b))
if args.csv:
writeCSV(jetStream3Breakdown(a), jetStream3Breakdown(b), args.csv, args.sort)
elif typeA == Speedometer2:
if args.detailed_breakdown:
dumpBreakdowns(speedometer2BreakdownSyncAsync(a), speedometer2BreakdownSyncAsync(b), args.sort)
if args.breakdown:
dumpBreakdowns(speedometer2Breakdown(a), speedometer2Breakdown(b), args.sort)
ttest(typeA, Speedometer2Results(a), Speedometer2Results(b))
if args.csv:
writeCSV(speedometer2Breakdown(a), speedometer2Breakdown(b), args.csv, args.sort)
elif typeA == Speedometer3:
if args.detailed_breakdown:
dumpBreakdowns(speedometer3BreakdownSyncAsync(a), speedometer3BreakdownSyncAsync(b), args.sort)
if args.breakdown:
dumpBreakdowns(speedometer3Breakdown(a), speedometer3Breakdown(b), args.sort)
ttest(typeA, Speedometer3Results(a), Speedometer3Results(b))
if args.csv:
writeCSV(speedometer3Breakdown(a), speedometer3Breakdown(b), args.csv, args.sort)
elif any(typeA == validMotionMarkTest for validMotionMarkTest in [MotionMark, MotionMark1_1, MotionMark1_1_1, MotionMark1_2, MotionMark1_3]):
if args.breakdown:
dumpBreakdowns(motionMarkBreakdown(a), motionMarkBreakdown(b), args.sort)
ttest(typeA, motionMarkResults(a), motionMarkResults(b))
if args.csv:
writeCSV(motionMarkBreakdown(a), motionMarkBreakdown(b), args.csv, args.sort)
elif typeA == PLT5:
if args.breakdown:
dumpBreakdowns(plt5Breakdown(a), plt5Breakdown(b), args.sort)
ttest(typeA, PLT5Results(a), PLT5Results(b))
if args.csv:
writeCSV(plt5Breakdown(a), plt5Breakdown(b), args.csv, args.sort)
elif typeA == CompetitivePLT:
if args.breakdown:
dumpBreakdowns(competitivePLTBreakdown(a), competitivePLTBreakdown(b), args.sort)
ttest(typeA, CompetitivePLTResults(a), CompetitivePLTResults(b))
if args.csv:
writeCSV(competitivePLTBreakdown(a), competitivePLTBreakdown(b), args.csv, args.sort)
elif typeA == PLUM3:
if args.breakdown:
dumpBreakdowns(plum3Breakdown(a), plum3Breakdown(b), args.sort)
ttest(typeA, PLUM3Results(a), PLUM3Results(b))
if args.csv:
writeCSV(plum3Breakdown(a), plum3Breakdown(b), args.csv)
elif typeA == RAMification:
if args.detailed_breakdown:
dumpBreakdowns(detailedRAMificationBreakdown(a), detailedRAMificationBreakdown(b), args.sort)
if args.breakdown:
dumpBreakdowns(ramificationBreakdown(a), ramificationBreakdown(b), args.sort)
ttest(typeA, RAMificationResults(a), RAMificationResults(b))
if args.csv:
writeCSV(ramificationBreakdown(a), ramificationBreakdown(b), args.csv, args.sort)
else:
print("Unknown benchmark type")
sys.exit(1)
if __name__ == "__main__":
main()