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.
5 """Apple's Speedometer performance benchmark.
7 Speedometer measures simulated user interactions in web applications.
9 The current benchmark uses TodoMVC to simulate user actions for adding,
10 completing, and removing to-do items. Speedometer repeats the same actions using
11 DOM APIs - a core set of web platform APIs used extensively in web applications-
12 as well as six popular JavaScript frameworks: Ember.js, Backbone.js, jQuery,
13 AngularJS, React, and Flight. Many of these frameworks are used on the most
14 popular websites in the world, such as Facebook and Twitter. The performance of
15 these types of operations depends on the speed of the DOM APIs, the JavaScript
16 engine, CSS style resolution, layout, and other technologies.
21 from core
import perf_benchmark
23 from telemetry
import page
as page_module
24 from telemetry
.page
import page_test
25 from telemetry
import story
26 from telemetry
.value
import list_of_scalar_values
28 from metrics
import keychain_metric
31 class SpeedometerMeasurement(page_test
.PageTest
):
43 super(SpeedometerMeasurement
, self
).__init
__()
45 def CustomizeBrowserOptions(self
, options
):
46 keychain_metric
.KeychainMetric
.CustomizeBrowserOptions(options
)
48 def ValidateAndMeasurePage(self
, page
, tab
, results
):
49 tab
.WaitForDocumentReadyStateToBeComplete()
51 # A single iteration on android takes ~75 seconds, the benchmark times out
52 # when running for 10 iterations.
53 if tab
.browser
.platform
.GetOSName() == 'android':
56 tab
.ExecuteJavaScript("""
57 // Store all the results in the benchmarkClient
58 benchmarkClient._measuredValues = []
59 benchmarkClient.didRunSuites = function(measuredValues) {
60 benchmarkClient._measuredValues.push(measuredValues);
61 benchmarkClient._timeValues.push(measuredValues.total);
63 benchmarkClient.iterationCount = %d;
66 tab
.WaitForJavaScriptExpression(
67 'benchmarkClient._finishedTestCount == benchmarkClient.testsCount', 600)
68 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
70 tab
.EvaluateJavaScript('benchmarkClient._timeValues'), important
=True))
72 # Extract the timings for each suite
73 for suite_name
in self
.enabled_suites
:
74 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
75 page
, suite_name
, 'ms',
76 tab
.EvaluateJavaScript("""
78 for(var i = 0; i < benchmarkClient.iterationCount; i++) {
80 benchmarkClient._measuredValues[i].tests['%s'].total);
83 """ % suite_name
), important
=False))
84 keychain_metric
.KeychainMetric().AddResults(tab
, results
)
86 class Speedometer(perf_benchmark
.PerfBenchmark
):
87 test
= SpeedometerMeasurement
93 def CreateStorySet(self
, options
):
95 base_dir
=os
.path
.dirname(os
.path
.abspath(__file__
)),
96 archive_data_file
='../page_sets/data/speedometer.json',
97 cloud_storage_bucket
=story
.PUBLIC_BUCKET
)
98 ps
.AddStory(page_module
.Page(
99 'http://browserbench.org/Speedometer/', ps
, ps
.base_dir
,
100 make_javascript_deterministic
=False))