[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / perf / benchmarks / dom_perf.py
blobb68620ac0f51b3f79d246b5aab3840f0a4b62140
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.
5 import json
6 import math
7 import os
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."""
20 if not values:
21 return None
22 # To avoid infinite value errors, make sure no value is less than 0.001.
23 new_values = []
24 for value in values:
25 if value > 0.001:
26 new_values.append(value)
27 else:
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):
42 def __init__(self):
43 super(_DomPerfMeasurement, self).__init__()
45 def ValidateAndMeasurePage(self, page, tab, results):
46 try:
47 def _IsDone():
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))
58 finally:
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,
70 total))
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
82 @classmethod
83 def Name(cls):
84 return 'dom_perf'
86 def CreatePageSet(self, options):
87 dom_perf_dir = os.path.join(util.GetChromiumSrcDir(), 'data', 'dom_perf')
88 run_params = [
89 'Accessors',
90 'CloneNodes',
91 'CreateNodes',
92 'DOMDivWalk',
93 'DOMTable',
94 'DOMWalk',
95 'Events',
96 'Get+Elements',
97 'GridSort',
98 'Template'
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))
104 return ps