Home | History | Annotate | Download | only in benchmarks
      1 # Copyright (c) 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.
      4 
      5 import json
      6 import math
      7 import os
      8 import sys
      9 
     10 from telemetry import test
     11 from telemetry.core import util
     12 from telemetry.page import page_measurement
     13 from telemetry.page import page_set
     14 from telemetry.value import merge_values
     15 
     16 
     17 def _GeometricMean(values):
     18   """Compute a rounded geometric mean from an array of values."""
     19   if not values:
     20     return None
     21   # To avoid infinite value errors, make sure no value is less than 0.001.
     22   new_values = []
     23   for value in values:
     24     if value > 0.001:
     25       new_values.append(value)
     26     else:
     27       new_values.append(0.001)
     28   # Compute the sum of the log of the values.
     29   log_sum = sum(map(math.log, new_values))
     30   # Raise e to that sum over the number of values.
     31   mean = math.pow(math.e, (log_sum / len(new_values)))
     32   # Return the rounded mean.
     33   return int(round(mean))
     34 
     35 
     36 SCORE_UNIT = 'score (bigger is better)'
     37 SCORE_TRACE_NAME = 'score'
     38 
     39 
     40 class _DomPerfMeasurement(page_measurement.PageMeasurement):
     41   @property
     42   def results_are_the_same_on_every_page(self):
     43     return False
     44 
     45   def MeasurePage(self, page, tab, results):
     46     try:
     47       def _IsDone():
     48         return tab.GetCookieByName('__domperf_finished') == '1'
     49       util.WaitFor(_IsDone, 600)
     50 
     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.Add(SCORE_TRACE_NAME, SCORE_UNIT,
     56                       suite['score'], suite['name'], 'unimportant')
     57     finally:
     58       tab.EvaluateJavaScript('document.cookie = "__domperf_finished=0"')
     59 
     60   def DidRunTest(self, browser, results):
     61     # Now give the geometric mean as the total for the combined runs.
     62     combined = merge_values.MergeLikeValuesFromDifferentPages(
     63         results.all_page_specific_values,
     64         group_by_name_suffix=True)
     65     combined_score = [x for x in combined if x.name == SCORE_TRACE_NAME][0]
     66     total = _GeometricMean(combined_score.values)
     67     results.AddSummary(SCORE_TRACE_NAME, SCORE_UNIT, total, 'Total')
     68 
     69 
     70 class DomPerf(test.Test):
     71   """A suite of JavaScript benchmarks for exercising the browser's DOM.
     72 
     73   The final score is computed as the geometric mean of the individual results.
     74   Scores are not comparable across benchmark suite versions and higher scores
     75   means better performance: Bigger is better!"""
     76   test = _DomPerfMeasurement
     77 
     78   enabled = not sys.platform.startswith('linux')
     79 
     80   def CreatePageSet(self, options):
     81     dom_perf_dir = os.path.join(util.GetChromiumSrcDir(), 'data', 'dom_perf')
     82     base_page = 'file://run.html?reportInJS=1&run='
     83     return page_set.PageSet.FromDict({
     84         'pages': [
     85           { 'url': base_page + 'Accessors' },
     86           { 'url': base_page + 'CloneNodes' },
     87           { 'url': base_page + 'CreateNodes' },
     88           { 'url': base_page + 'DOMDivWalk' },
     89           { 'url': base_page + 'DOMTable' },
     90           { 'url': base_page + 'DOMWalk' },
     91           { 'url': base_page + 'Events' },
     92           { 'url': base_page + 'Get+Elements' },
     93           { 'url': base_page + 'GridSort' },
     94           { 'url': base_page + 'Template' }
     95           ]
     96         }, dom_perf_dir)
     97