1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
9 from telemetry
import benchmark
10 from telemetry
.core
import util
11 from telemetry
import page
as page_module
12 from telemetry
.page
import page_set
13 from telemetry
.page
import page_test
14 from telemetry
.value
import merge_values
15 from telemetry
.value
import scalar
18 def _GeometricMean(values
):
19 """Compute a rounded geometric mean from an array of values."""
22 # To avoid infinite value errors, make sure no value is less than 0.001.
26 new_values
.append(value
)
28 new_values
.append(0.001)
29 # Compute the sum of the log of the values.
30 log_sum
= sum(map(math
.log
, new_values
))
31 # Raise e to that sum over the number of values.
32 mean
= math
.pow(math
.e
, (log_sum
/ len(new_values
)))
33 # Return the rounded mean.
34 return int(round(mean
))
37 SCORE_UNIT
= 'score (bigger is better)'
38 SCORE_TRACE_NAME
= 'score'
41 class _DomPerfMeasurement(page_test
.PageTest
):
43 super(_DomPerfMeasurement
, self
).__init
__()
45 def ValidateAndMeasurePage(self
, page
, tab
, results
):
48 return tab
.GetCookieByName('__domperf_finished') == '1'
49 util
.WaitFor(_IsDone
, 600)
51 data
= json
.loads(tab
.EvaluateJavaScript('__domperf_result'))
52 for suite
in data
['BenchmarkSuites']:
53 # Skip benchmarks that we didn't actually run this time around.
54 if len(suite
['Benchmarks']) or suite
['score']:
55 results
.AddValue(scalar
.ScalarValue(
56 results
.current_page
, '%s.%s' % (suite
['name'], SCORE_TRACE_NAME
),
57 SCORE_UNIT
, suite
['score'], important
=False))
59 tab
.EvaluateJavaScript('document.cookie = "__domperf_finished=0"')
61 def DidRunTest(self
, browser
, results
):
62 # Now give the geometric mean as the total for the combined runs.
63 combined
= merge_values
.MergeLikeValuesFromDifferentPages(
64 results
.all_page_specific_values
,
65 group_by_name_suffix
=True)
66 combined_score
= [x
for x
in combined
if x
.name
== SCORE_TRACE_NAME
][0]
67 total
= _GeometricMean(combined_score
.values
)
68 results
.AddSummaryValue(
69 scalar
.ScalarValue(None, 'Total.' + SCORE_TRACE_NAME
, SCORE_UNIT
,
73 @benchmark.Disabled('android', 'linux') # http://crbug.com/458540
74 class DomPerf(benchmark
.Benchmark
):
75 """A suite of JavaScript benchmarks for exercising the browser's DOM.
77 The final score is computed as the geometric mean of the individual results.
78 Scores are not comparable across benchmark suite versions and higher scores
79 means better performance: Bigger is better!"""
80 test
= _DomPerfMeasurement
86 def CreatePageSet(self
, options
):
87 dom_perf_dir
= os
.path
.join(util
.GetChromiumSrcDir(), 'data', 'dom_perf')
100 ps
= page_set
.PageSet(file_path
=dom_perf_dir
)
101 for param
in run_params
:
102 ps
.AddUserStory(page_module
.Page(
103 'file://run.html?reportInJS=1&run=%s' % param
, ps
, ps
.base_dir
))