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