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 Mozilla's Kraken JavaScript benchmark.""" 6 7 import os 8 9 from telemetry import test 10 from telemetry.page import page_measurement 11 from telemetry.page import page_set 12 13 14 def _Mean(l): 15 return float(sum(l)) / len(l) if len(l) > 0 else 0.0 16 17 18 class _KrakenMeasurement(page_measurement.PageMeasurement): 19 def MeasurePage(self, _, tab, results): 20 tab.WaitForDocumentReadyStateToBeComplete() 21 tab.WaitForJavaScriptExpression( 22 'document.title.indexOf("Results") != -1', 500) 23 24 js_get_results = """ 25 var formElement = document.getElementsByTagName("input")[0]; 26 decodeURIComponent(formElement.value.split("?")[1]); 27 """ 28 result_dict = eval(tab.EvaluateJavaScript(js_get_results)) 29 total = 0 30 for key in result_dict: 31 if key == 'v': 32 continue 33 results.Add(key, 'ms', result_dict[key], data_type='unimportant') 34 total += _Mean(result_dict[key]) 35 results.Add('Total', 'ms', total) 36 37 38 class Kraken(test.Test): 39 """Mozilla's Kraken JavaScript benchmark.""" 40 test = _KrakenMeasurement 41 42 def CreatePageSet(self, options): 43 return page_set.PageSet.FromDict({ 44 'archive_data_file': '../page_sets/data/kraken.json', 45 'pages': [ 46 { 'url': 'http://krakenbenchmark.mozilla.org/kraken-1.1/driver.html' } 47 ] 48 }, os.path.abspath(__file__)) 49