053f601322dcb39972be5ac163aedbfefcc8e148
[platform/framework/web/crosswalk.git] / src / tools / perf / benchmarks / octane.py
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.
4
5 """Runs Octane 2.0 javascript benchmark.
6
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.
12 """
13
14 import os
15
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
22
23 _GB = 1024 * 1024 * 1024
24
25 class _OctaneMeasurement(page_measurement.PageMeasurement):
26   def __init__(self):
27     super(_OctaneMeasurement, self).__init__()
28     self._power_metric = power.PowerMetric()
29
30   def CustomizeBrowserOptions(self, options):
31     power.PowerMetric.CustomizeBrowserOptions(options)
32
33
34   def WillNavigateToPage(self, page, tab):
35     if tab.browser.memory_stats['SystemTotalPhysicalMemory'] < 1 * _GB:
36       skipBenchmarks = '"zlib"'
37     else:
38       skipBenchmarks = ''
39     page.script_to_evaluate_on_commit = """
40         var __results = [];
41         var __real_log = window.console.log;
42         window.console.log = function(msg) {
43           __results.push(msg);
44           __real_log.apply(this, [msg]);
45         }
46         skipBenchmarks = [%s]
47         """ % (skipBenchmarks)
48
49   def DidNavigateToPage(self, page, tab):
50     self._power_metric.Start(page, tab)
51
52   def MeasurePage(self, page, tab, results):
53     tab.WaitForJavaScriptExpression(
54         'completed && !document.getElementById("progress-bar-container")', 1200)
55
56     self._power_metric.Stop(page, tab)
57     self._power_metric.AddResults(tab, results)
58
59     results_log = tab.EvaluateJavaScript('__results')
60     all_scores = []
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))
76
77
78 class Octane(test.Test):
79   """Google's Octane JavaScript benchmark."""
80   test = _OctaneMeasurement
81
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,
86       'pages': [{
87           'url':
88           'http://octane-benchmark.googlecode.com/svn/latest/index.html?auto=1'
89           }
90         ]
91       }, os.path.abspath(__file__))