1# Copyright 2014 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"""Apple's Speedometer performance benchmark. 6 7Speedometer measures simulated user interactions in web applications. 8 9The current benchmark uses TodoMVC to simulate user actions for adding, 10completing, and removing to-do items. Speedometer repeats the same actions using 11DOM APIs - a core set of web platform APIs used extensively in web applications- 12as well as six popular JavaScript frameworks: Ember.js, Backbone.js, jQuery, 13AngularJS, React, and Flight. Many of these frameworks are used on the most 14popular websites in the world, such as Facebook and Twitter. The performance of 15these types of operations depends on the speed of the DOM APIs, the JavaScript 16engine, CSS style resolution, layout, and other technologies. 17""" 18 19import os 20 21from telemetry import benchmark 22from telemetry.page import page_set 23from telemetry.page import page_test 24from telemetry.value import list_of_scalar_values 25 26 27class SpeedometerMeasurement(page_test.PageTest): 28 enabled_suites = [ 29 'VanillaJS-TodoMVC', 30 'EmberJS-TodoMVC', 31 'BackboneJS-TodoMVC', 32 'jQuery-TodoMVC', 33 'AngularJS-TodoMVC', 34 'React-TodoMVC', 35 'FlightJS-TodoMVC' 36 ] 37 38 def ValidateAndMeasurePage(self, page, tab, results): 39 tab.WaitForDocumentReadyStateToBeComplete() 40 iterationCount = 10 41 # A single iteration on android takes ~75 seconds, the benchmark times out 42 # when running for 10 iterations. 43 if tab.browser.platform.GetOSName() == 'android': 44 iterationCount = 3 45 46 tab.ExecuteJavaScript(""" 47 // Store all the results in the benchmarkClient 48 benchmarkClient._measuredValues = [] 49 benchmarkClient.didRunSuites = function(measuredValues) { 50 benchmarkClient._measuredValues.push(measuredValues); 51 benchmarkClient._timeValues.push(measuredValues.total); 52 }; 53 benchmarkClient.iterationCount = %d; 54 startTest(); 55 """ % iterationCount) 56 tab.WaitForJavaScriptExpression( 57 'benchmarkClient._finishedTestCount == benchmarkClient.testsCount', 600) 58 results.AddValue(list_of_scalar_values.ListOfScalarValues( 59 page, 'Total', 'ms', 60 tab.EvaluateJavaScript('benchmarkClient._timeValues'), important=True)) 61 62 # Extract the timings for each suite 63 for suite_name in self.enabled_suites: 64 results.AddValue(list_of_scalar_values.ListOfScalarValues( 65 page, suite_name, 'ms', 66 tab.EvaluateJavaScript(""" 67 var suite_times = []; 68 for(var i = 0; i < benchmarkClient.iterationCount; i++) { 69 suite_times.push( 70 benchmarkClient._measuredValues[i].tests['%s'].total); 71 }; 72 suite_times; 73 """ % suite_name), important=False)) 74 75class Speedometer(benchmark.Benchmark): 76 test = SpeedometerMeasurement 77 78 def CreatePageSet(self, options): 79 ps = page_set.PageSet( 80 file_path=os.path.abspath(__file__), 81 archive_data_file='../page_sets/data/speedometer.json', 82 make_javascript_deterministic=False) 83 ps.AddPageWithDefaultRunNavigate('http://browserbench.org/Speedometer/') 84 return ps 85