1 # Copyright 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.
5 """Runs Mozilla's Kraken JavaScript benchmark."""
9 from telemetry
import benchmark
10 from telemetry
import page
as page_module
11 from telemetry
.page
import page_set
12 from telemetry
.page
import page_test
13 from telemetry
.value
import list_of_scalar_values
14 from telemetry
.value
import scalar
16 from metrics
import power
21 'This benchmark uses the [A* search algorithm]'
22 '(http://en.wikipedia.org/wiki/A*_search_algorithm) to automatically '
23 'plot an efficient path between two points, in the presence of '
24 'obstacles. Adapted from code by [Brian Gringstead]'
25 '(http://www.briangrinstead.com/blog/astar-search-algorithm-in-'
27 'audio-beat-detection':
28 'This benchmark performs [beat detection]'
29 '(http://en.wikipedia.org/wiki/Beat_detection) on an Audio sample '
30 'using [code](http://beatdetektor.svn.sourceforge.net/viewvc'
31 '/beatdetektor/trunk/core/js/beatdetektor.js?revision=18&view=markup) '
32 'from [BeatDetektor](http://www.cubicproductions.com/index.php'
33 '?option=com_content&view=article&id=67&Itemid=82) and '
34 '[DSP.js](http://github.com/corbanbrook/dsp.js/).',
36 'This benchmark performs a [Discrete Fourier Transform]'
37 '(http://en.wikipedia.org/wiki/Discrete_Fourier_transform) on an '
38 'Audio sample using code from [DSP.js]'
39 '(http://github.com/corbanbrook/dsp.js).',
41 'This benchmark performs a [Fast Fourier Transform]'
42 '(http://en.wikipedia.org/wiki/Fast_Fourier_transform) on an Audio '
43 'sample using code from [DSP.js]'
44 '(http://github.com/corbanbrook/dsp.js/).',
46 'This benchmark generates a soundwave using code from [DSP.js]'
47 '(http://github.com/corbanbrook/dsp.js/).',
49 'This benchmark performs a variety of photo manipulations such as '
50 'Fill, Brightness, Contrast, Saturation, and Temperature.',
52 'This benchmark [desaturates]'
53 '(http://en.wikipedia.org/wiki/Colorfulness) a photo using code from '
54 '[Pixastic](http://www.pixastic.com/).',
55 'imaging-gaussian-blur':
56 'This benchmark performs a [Gaussian blur]'
57 '(http://en.wikipedia.org/wiki/Gaussian_blur) on a photo.',
58 'json-parse-financial':
59 'This benchmark parses [JSON](http://www.json.org) records.',
60 'json-stringify-tinderbox':
61 'This benchmark serializes [Tinderbox]'
62 '(http://tests.themasta.com/tinderboxpushlog/?tree=Firefox) build '
63 'data to [JSON](http://www.json.org).',
68 return float(sum(l
)) / len(l
) if len(l
) > 0 else 0.0
71 class _KrakenMeasurement(page_test
.PageTest
):
73 super(_KrakenMeasurement
, self
).__init
__()
74 self
._power
_metric
= None
76 def CustomizeBrowserOptions(self
, options
):
77 power
.PowerMetric
.CustomizeBrowserOptions(options
)
79 def WillStartBrowser(self
, platform
):
80 self
._power
_metric
= power
.PowerMetric(platform
)
82 def DidNavigateToPage(self
, page
, tab
):
83 self
._power
_metric
.Start(page
, tab
)
85 def ValidateAndMeasurePage(self
, page
, tab
, results
):
86 tab
.WaitForJavaScriptExpression(
87 'document.title.indexOf("Results") != -1', 700)
88 tab
.WaitForDocumentReadyStateToBeComplete()
90 self
._power
_metric
.Stop(page
, tab
)
91 self
._power
_metric
.AddResults(tab
, results
)
94 var formElement = document.getElementsByTagName("input")[0];
95 decodeURIComponent(formElement.value.split("?")[1]);
97 result_dict
= eval(tab
.EvaluateJavaScript(js_get_results
))
99 for key
in result_dict
:
102 results
.AddValue(list_of_scalar_values
.ListOfScalarValues(
103 results
.current_page
, key
, 'ms', result_dict
[key
], important
=False,
104 description
=DESCRIPTIONS
.get(key
)))
105 total
+= _Mean(result_dict
[key
])
107 # TODO(tonyg/nednguyen): This measurement shouldn't calculate Total. The
108 # results system should do that for us.
109 results
.AddValue(scalar
.ScalarValue(
110 results
.current_page
, 'Total', 'ms', total
,
111 description
='Total of the means of the results for each type '
112 'of benchmark in [Mozilla\'s Kraken JavaScript benchmark]'
113 '(http://krakenbenchmark.mozilla.org/)'))
116 class Kraken(benchmark
.Benchmark
):
117 """Mozilla's Kraken JavaScript benchmark.
119 http://krakenbenchmark.mozilla.org/
121 test
= _KrakenMeasurement
127 def CreatePageSet(self
, options
):
128 ps
= page_set
.PageSet(
129 archive_data_file
='../page_sets/data/kraken.json',
130 file_path
=os
.path
.abspath(__file__
),
131 bucket
=page_set
.PARTNER_BUCKET
)
132 ps
.AddUserStory(page_module
.Page(
133 'http://krakenbenchmark.mozilla.org/kraken-1.1/driver.html',