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
3 # found in the LICENSE file.
8 from telemetry
import benchmark
9 from telemetry
import page
as page_module
10 from telemetry
.page
import page_set
11 from telemetry
.page
import page_test
12 from telemetry
.value
import list_of_scalar_values
14 from metrics
import power
17 _URL
= 'http://www.webkit.org/perf/sunspider-1.0.2/sunspider-1.0.2/driver.html'
21 'Pure JavaScript computations of the kind you might use to do 3d '
22 'rendering, but without the rendering. This ends up mostly hitting '
23 'floating point math and array access.',
25 'Pure JavaScript computations of the kind you might use to do 3d '
26 'rendering, but without the rendering. This ends up mostly hitting '
27 'floating point math and array access.',
29 'Pure JavaScript computations of the kind you might use to do 3d '
30 'rendering, but without the rendering. This ends up mostly hitting '
31 'floating point math and array access.',
32 'access-binary-trees': 'Array, object property and variable access.',
33 'access-fannkuch': 'Array, object property and variable access.',
34 'access-nbody': 'Array, object property and variable access.',
35 'access-nsieve': 'Array, object property and variable access.',
36 'bitops-3bit-bits-in-byte':
37 'Bitwise operations, these can be useful for various things '
38 'including games, mathematical computations, and various kinds of '
39 'encoding/decoding. It\'s also the only kind of math in JavaScript '
40 'that is done as integer, not floating point.',
41 'bitops-bits-in-byte':
42 'Bitwise operations, these can be useful for various things '
43 'including games, mathematical computations, and various kinds of '
44 'encoding/decoding. It\'s also the only kind of math in JavaScript '
45 'that is done as integer, not floating point.',
47 'Bitwise operations, these can be useful for various things '
48 'including games, mathematical computations, and various kinds of '
49 'encoding/decoding. It\'s also the only kind of math in JavaScript '
50 'that is done as integer, not floating point.',
52 'Bitwise operations, these can be useful for various things '
53 'including games, mathematical computations, and various kinds of '
54 'encoding/decoding. It\'s also the only kind of math in JavaScript '
55 'that is done as integer, not floating point.',
56 'controlflow-recursive':
57 'Control flow constructs (looping, recursion, conditionals). Right '
58 'now it mostly covers recursion, as the others are pretty well covered '
60 'crypto-aes': 'Real cryptography code related to AES.',
61 'crypto-md5': 'Real cryptography code related to MD5.',
62 'crypto-sha1': 'Real cryptography code related to SHA1.',
63 'date-format-tofte': 'Performance of JavaScript\'s "date" objects.',
64 'date-format-xparb': 'Performance of JavaScript\'s "date" objects.',
65 'math-cordic': 'Various mathematical type computations.',
66 'math-partial-sums': 'Various mathematical type computations.',
67 'math-spectral-norm': 'Various mathematical type computations.',
68 'regexp-dna': 'Regular expressions performance.',
69 'string-base64': 'String processing.',
70 'string-fasta': 'String processing',
71 'string-tagcloud': 'String processing code to generate a giant "tagcloud".',
72 'string-unpack-code': 'String processing code to extracting compressed JS.',
73 'string-validate-input': 'String processing.',
77 class _SunspiderMeasurement(page_test
.PageTest
):
79 super(_SunspiderMeasurement
, self
).__init
__()
80 self
._power
_metric
= None
82 def CustomizeBrowserOptions(self
, options
):
83 power
.PowerMetric
.CustomizeBrowserOptions(options
)
85 def WillStartBrowser(self
, platform
):
86 self
._power
_metric
= power
.PowerMetric(platform
)
88 def DidNavigateToPage(self
, page
, tab
):
89 self
._power
_metric
.Start(page
, tab
)
91 def ValidateAndMeasurePage(self
, page
, tab
, results
):
92 tab
.WaitForJavaScriptExpression(
93 'window.location.pathname.indexOf("results.html") >= 0'
94 '&& typeof(output) != "undefined"', 300)
96 self
._power
_metric
.Stop(page
, tab
)
97 self
._power
_metric
.AddResults(tab
, results
)
99 js_get_results
= 'JSON.stringify(output);'
100 js_results
= json
.loads(tab
.EvaluateJavaScript(js_get_results
))
102 # Below, r is a map of benchmark names to lists of result numbers,
103 # and totals is a list of totals of result numbers.
104 # js_results is: formatted like this:
106 # {'3d-cube': v1, '3d-morph': v2, ...},
107 # {'3d-cube': v3, '3d-morph': v4, ...},
110 r
= collections
.defaultdict(list)
112 for result
in js_results
:
114 for key
, value
in result
.iteritems():
118 for key
, values
in r
.iteritems():
119 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
120 results
.current_page
, key
, 'ms', values
, important
=False,
121 description
=DESCRIPTIONS
.get(key
)))
122 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
123 results
.current_page
, 'Total', 'ms', totals
,
124 description
='Totals of run time for each different type of benchmark '
128 class Sunspider(benchmark
.Benchmark
):
129 """Apple's SunSpider JavaScript benchmark.
131 http://www.webkit.org/perf/sunspider/sunspider.html
133 test
= _SunspiderMeasurement
139 def CreatePageSet(self
, options
):
140 ps
= page_set
.PageSet(
141 archive_data_file
='../page_sets/data/sunspider.json',
142 file_path
=os
.path
.abspath(__file__
),
143 bucket
=page_set
.PARTNER_BUCKET
)
144 ps
.AddUserStory(page_module
.Page(
145 _URL
, ps
, ps
.base_dir
, make_javascript_deterministic
=False))