1 # Copyright (c) 2012 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 """Runs Octane 2.0 javascript benchmark.
7 Octane 2.0 is a modern benchmark that measures a JavaScript engine's performance
8 by running a suite of tests representative of today's complex and demanding web
9 applications. Octane's goal is to measure the performance of JavaScript code
10 found in large, real-world web applications.
11 Octane 2.0 consists of 17 tests, four more than Octane v1.
16 from metrics import power
17 from telemetry import test
18 from telemetry.page import page_measurement
19 from telemetry.page import page_set
20 from telemetry.util import statistics
21 from telemetry.value import scalar
23 _GB = 1024 * 1024 * 1024
25 class _OctaneMeasurement(page_measurement.PageMeasurement):
27 super(_OctaneMeasurement, self).__init__()
28 self._power_metric = power.PowerMetric()
30 def CustomizeBrowserOptions(self, options):
31 power.PowerMetric.CustomizeBrowserOptions(options)
34 def WillNavigateToPage(self, page, tab):
35 if tab.browser.memory_stats['SystemTotalPhysicalMemory'] < 1 * _GB:
36 skipBenchmarks = '"zlib"'
39 page.script_to_evaluate_on_commit = """
41 var __real_log = window.console.log;
42 window.console.log = function(msg) {
44 __real_log.apply(this, [msg]);
47 """ % (skipBenchmarks)
49 def DidNavigateToPage(self, page, tab):
50 self._power_metric.Start(page, tab)
52 def MeasurePage(self, page, tab, results):
53 tab.WaitForJavaScriptExpression(
54 'completed && !document.getElementById("progress-bar-container")', 1200)
56 self._power_metric.Stop(page, tab)
57 self._power_metric.AddResults(tab, results)
59 results_log = tab.EvaluateJavaScript('__results')
61 for output in results_log:
62 # Split the results into score and test name.
63 # results log e.g., "Richards: 18343"
64 score_and_name = output.split(': ', 2)
65 assert len(score_and_name) == 2, \
66 'Unexpected result format "%s"' % score_and_name
67 if 'Skipped' not in score_and_name[1]:
68 name = score_and_name[0]
69 score = int(score_and_name[1])
70 results.Add(name, 'score', score, data_type='unimportant')
71 # Collect all test scores to compute geometric mean.
72 all_scores.append(score)
73 total = statistics.GeometricMean(all_scores)
74 results.AddSummaryValue(
75 scalar.ScalarValue(None, 'Total.Score', 'score', total))
78 class Octane(test.Test):
79 """Google's Octane JavaScript benchmark."""
80 test = _OctaneMeasurement
82 def CreatePageSet(self, options):
83 return page_set.PageSet.FromDict({
84 'archive_data_file': '../page_sets/data/octane.json',
85 'make_javascript_deterministic': False,
88 'http://octane-benchmark.googlecode.com/svn/latest/index.html?auto=1'
91 }, os.path.abspath(__file__))