OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 import collections | 4 import collections |
5 import json | 5 import json |
6 import os | 6 import os |
7 | 7 |
8 from metrics import power | 8 from metrics import power |
9 from telemetry import benchmark | 9 from telemetry import benchmark |
10 from telemetry.page import page_measurement | 10 from telemetry.page import page_measurement |
11 from telemetry.page import page_set | 11 from telemetry.page import page_set |
12 from telemetry.value import list_of_scalar_values | 12 from telemetry.value import list_of_scalar_values |
13 | 13 |
14 | 14 |
15 _URL = 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html' | 15 _URL = 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html' |
16 | 16 |
| 17 DESCRIPTIONS = { |
| 18 '3d-cube': |
| 19 'Pure JavaScript computations of the kind you might use to do 3d ' |
| 20 'rendering, but without the rendering. This ends up mostly hitting ' |
| 21 'floating point math and array access.', |
| 22 '3d-morph': |
| 23 'Pure JavaScript computations of the kind you might use to do 3d ' |
| 24 'rendering, but without the rendering. This ends up mostly hitting ' |
| 25 'floating point math and array access.', |
| 26 '3d-raytrace': |
| 27 'Pure JavaScript computations of the kind you might use to do 3d ' |
| 28 'rendering, but without the rendering. This ends up mostly hitting ' |
| 29 'floating point math and array access.', |
| 30 'access-binary-trees': 'Array, object property and variable access.', |
| 31 'access-fannkuch': 'Array, object property and variable access.', |
| 32 'access-nbody': 'Array, object property and variable access.', |
| 33 'access-nsieve': 'Array, object property and variable access.', |
| 34 'bitops-3bit-bits-in-byte': |
| 35 'Bitwise operations, these can be useful for various things ' |
| 36 'including games, mathematical computations, and various kinds of ' |
| 37 'encoding/decoding. It\'s also the only kind of math in JavaScript ' |
| 38 'that is done as integer, not floating point.', |
| 39 'bitops-bits-in-byte': |
| 40 'Bitwise operations, these can be useful for various things ' |
| 41 'including games, mathematical computations, and various kinds of ' |
| 42 'encoding/decoding. It\'s also the only kind of math in JavaScript ' |
| 43 'that is done as integer, not floating point.', |
| 44 'bitops-bitwise-and': |
| 45 'Bitwise operations, these can be useful for various things ' |
| 46 'including games, mathematical computations, and various kinds of ' |
| 47 'encoding/decoding. It\'s also the only kind of math in JavaScript ' |
| 48 'that is done as integer, not floating point.', |
| 49 'bitops-nsieve-bits': |
| 50 'Bitwise operations, these can be useful for various things ' |
| 51 'including games, mathematical computations, and various kinds of ' |
| 52 'encoding/decoding. It\'s also the only kind of math in JavaScript ' |
| 53 'that is done as integer, not floating point.', |
| 54 'controlflow-recursive': |
| 55 'Control flow constructs (looping, recursion, conditionals). Right ' |
| 56 'now it mostly covers recursion, as the others are pretty well covered ' |
| 57 'by other tests.', |
| 58 'crypto-aes': 'Real cryptography code related to AES.', |
| 59 'crypto-md5': 'Real cryptography code related to MD5.', |
| 60 'crypto-sha1': 'Real cryptography code related to SHA1.', |
| 61 'date-format-tofte': 'Performance of JavaScript\'s "date" objects.', |
| 62 'date-format-xparb': 'Performance of JavaScript\'s "date" objects.', |
| 63 'math-cordic': 'Various mathematical type computations.', |
| 64 'math-partial-sums': 'Various mathematical type computations.', |
| 65 'math-spectral-norm': 'Various mathematical type computations.', |
| 66 'regexp-dna': 'Regular expressions performance.', |
| 67 'string-base64': 'String processing.', |
| 68 'string-fasta': 'String processing', |
| 69 'string-tagcloud': 'String processing code to generate a giant "tagcloud".', |
| 70 'string-unpack-code': 'String processing code to extracting compressed JS.', |
| 71 'string-validate-input': 'String processing.', |
| 72 } |
| 73 |
17 | 74 |
18 class _SunspiderMeasurement(page_measurement.PageMeasurement): | 75 class _SunspiderMeasurement(page_measurement.PageMeasurement): |
19 def __init__(self): | 76 def __init__(self): |
20 super(_SunspiderMeasurement, self).__init__() | 77 super(_SunspiderMeasurement, self).__init__() |
21 self._power_metric = None | 78 self._power_metric = None |
22 | 79 |
23 def CustomizeBrowserOptions(self, options): | 80 def CustomizeBrowserOptions(self, options): |
24 power.PowerMetric.CustomizeBrowserOptions(options) | 81 power.PowerMetric.CustomizeBrowserOptions(options) |
25 | 82 |
26 def WillStartBrowser(self, browser): | 83 def WillStartBrowser(self, browser): |
27 self._power_metric = power.PowerMetric(browser) | 84 self._power_metric = power.PowerMetric(browser) |
28 | 85 |
29 def DidNavigateToPage(self, page, tab): | 86 def DidNavigateToPage(self, page, tab): |
30 self._power_metric.Start(page, tab) | 87 self._power_metric.Start(page, tab) |
31 | 88 |
32 def MeasurePage(self, page, tab, results): | 89 def MeasurePage(self, page, tab, results): |
33 tab.WaitForJavaScriptExpression( | 90 tab.WaitForJavaScriptExpression( |
34 'window.location.pathname.indexOf("results.html") >= 0' | 91 'window.location.pathname.indexOf("results.html") >= 0' |
35 '&& typeof(output) != "undefined"', 300) | 92 '&& typeof(output) != "undefined"', 300) |
36 | 93 |
37 self._power_metric.Stop(page, tab) | 94 self._power_metric.Stop(page, tab) |
38 self._power_metric.AddResults(tab, results) | 95 self._power_metric.AddResults(tab, results) |
39 | 96 |
40 js_get_results = 'JSON.stringify(output);' | 97 js_get_results = 'JSON.stringify(output);' |
41 js_results = json.loads(tab.EvaluateJavaScript(js_get_results)) | 98 js_results = json.loads(tab.EvaluateJavaScript(js_get_results)) |
| 99 |
| 100 # Below, r is a map of benchmark names to lists of result numbers, |
| 101 # and totals is a list of totals of result numbers. |
| 102 # js_results is: formatted like this: |
| 103 # [ |
| 104 # {'3d-cube': v1, '3d-morph': v2, ...}, |
| 105 # {'3d-cube': v3, '3d-morph': v4, ...}, |
| 106 # ... |
| 107 # ] |
42 r = collections.defaultdict(list) | 108 r = collections.defaultdict(list) |
43 totals = [] | 109 totals = [] |
44 # js_results is: [{'foo': v1, 'bar': v2}, | |
45 # {'foo': v3, 'bar': v4}, | |
46 # ...] | |
47 for result in js_results: | 110 for result in js_results: |
48 total = 0 | 111 total = 0 |
49 for key, value in result.iteritems(): | 112 for key, value in result.iteritems(): |
50 r[key].append(value) | 113 r[key].append(value) |
51 total += value | 114 total += value |
52 totals.append(total) | 115 totals.append(total) |
53 for key, values in r.iteritems(): | 116 for key, values in r.iteritems(): |
54 results.AddValue(list_of_scalar_values.ListOfScalarValues( | 117 results.AddValue(list_of_scalar_values.ListOfScalarValues( |
55 results.current_page, key, 'ms', values, important=False)) | 118 results.current_page, key, 'ms', values, important=False, |
| 119 description=DESCRIPTIONS.get(key))) |
56 results.AddValue(list_of_scalar_values.ListOfScalarValues( | 120 results.AddValue(list_of_scalar_values.ListOfScalarValues( |
57 results.current_page, 'Total', 'ms', totals)) | 121 results.current_page, 'Total', 'ms', totals, |
| 122 description='Totals of run time for each different type of benchmark ' |
| 123 'in sunspider')) |
58 | 124 |
59 | 125 |
60 class Sunspider(benchmark.Benchmark): | 126 class Sunspider(benchmark.Benchmark): |
61 """Apple's SunSpider JavaScript benchmark.""" | 127 """Apple's SunSpider JavaScript benchmark.""" |
62 test = _SunspiderMeasurement | 128 test = _SunspiderMeasurement |
63 | 129 |
64 def CreatePageSet(self, options): | 130 def CreatePageSet(self, options): |
65 ps = page_set.PageSet( | 131 ps = page_set.PageSet( |
66 archive_data_file='../page_sets/data/sunspider.json', | 132 archive_data_file='../page_sets/data/sunspider.json', |
67 make_javascript_deterministic=False, | 133 make_javascript_deterministic=False, |
68 file_path=os.path.abspath(__file__)) | 134 file_path=os.path.abspath(__file__)) |
69 ps.AddPageWithDefaultRunNavigate(_URL) | 135 ps.AddPageWithDefaultRunNavigate(_URL) |
70 return ps | 136 return ps |
OLD | NEW |