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 statistics 17 from telemetry import test 18 from telemetry.page import page_measurement 19 from telemetry.page import page_set 20 21 22 class _OctaneMeasurement(page_measurement.PageMeasurement): 23 24 def WillNavigateToPage(self, page, tab): 25 page.script_to_evaluate_on_commit = """ 26 var __results = []; 27 var __real_log = window.console.log; 28 window.console.log = function(msg) { 29 __results.push(msg); 30 __real_log.apply(this, [msg]); 31 } 32 """ 33 34 def MeasurePage(self, _, tab, results): 35 tab.WaitForJavaScriptExpression( 36 'completed && !document.getElementById("progress-bar-container")', 1200) 37 38 results_log = tab.EvaluateJavaScript('__results') 39 all_scores = [] 40 for output in results_log: 41 # Split the results into score and test name. 42 # results log e.g., "Richards: 18343" 43 score_and_name = output.split(': ', 2) 44 assert len(score_and_name) == 2, \ 45 'Unexpected result format "%s"' % score_and_name 46 name = score_and_name[0] 47 score = int(score_and_name[1]) 48 results.Add(name, 'score', score, data_type='unimportant') 49 # Collect all test scores to compute geometric mean. 50 all_scores.append(score) 51 total = statistics.GeometricMean(all_scores) 52 results.AddSummary('Score', 'score', total, chart_name='Total') 53 54 55 class Octane(test.Test): 56 """Google's Octane JavaScript benchmark.""" 57 test = _OctaneMeasurement 58 59 def CreatePageSet(self, options): 60 return page_set.PageSet.FromDict({ 61 'archive_data_file': '../page_sets/data/octane.json', 62 'make_javascript_deterministic': False, 63 'pages': [{ 64 'url': 65 'http://octane-benchmark.googlecode.com/svn/latest/index.html?auto=1' 66 } 67 ] 68 }, os.path.abspath(__file__)) 69 70