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