OLD | NEW |
| (Empty) |
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 Apple's SunSpider JavaScript benchmark.""" | |
6 | |
7 import collections | |
8 import json | |
9 import os | |
10 | |
11 from telemetry.core import util | |
12 from telemetry.page import page_measurement | |
13 from telemetry.page import page_set | |
14 | |
15 class SunSpiderMeasurement(page_measurement.PageMeasurement): | |
16 def CreatePageSet(self, _, options): | |
17 return page_set.PageSet.FromDict({ | |
18 'serving_dirs': ['../../../chrome/test/data/sunspider/'], | |
19 'pages': [ | |
20 { 'url': 'file:///../../../chrome/test/data/sunspider/' | |
21 'sunspider-1.0/driver.html' } | |
22 ] | |
23 }, os.path.abspath(__file__)) | |
24 | |
25 def MeasurePage(self, _, tab, results): | |
26 js_is_done = """ | |
27 window.location.pathname.indexOf('results.html') >= 0""" | |
28 def _IsDone(): | |
29 return tab.EvaluateJavaScript(js_is_done) | |
30 util.WaitFor(_IsDone, 300, poll_interval=5) | |
31 | |
32 js_get_results = 'JSON.stringify(output);' | |
33 js_results = json.loads(tab.EvaluateJavaScript(js_get_results)) | |
34 r = collections.defaultdict(list) | |
35 totals = [] | |
36 # js_results is: [{'foo': v1, 'bar': v2}, | |
37 # {'foo': v3, 'bar': v4}, | |
38 # ...] | |
39 for result in js_results: | |
40 total = 0 | |
41 for key, value in result.iteritems(): | |
42 r[key].append(value) | |
43 total += value | |
44 totals.append(total) | |
45 for key, values in r.iteritems(): | |
46 results.Add(key, 'ms', values, data_type='unimportant') | |
47 results.Add('Total', 'ms', totals) | |
OLD | NEW |