[Android WebViewShell] Add inclusion test for webview exposed stable interfaces.
[chromium-blink-merge.git] / tools / perf / benchmarks / kraken.py
blobad3ce62890c5f865d7a299b82bf63b30379cfc30
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."""
7 import os
9 from core import perf_benchmark
11 from telemetry import page as page_module
12 from telemetry.page import page_test
13 from telemetry import story
14 from telemetry.value import list_of_scalar_values
15 from telemetry.value import scalar
17 from metrics import power
20 DESCRIPTIONS = {
21 'ai-astar':
22 'This benchmark uses the [A* search algorithm]'
23 '(http://en.wikipedia.org/wiki/A*_search_algorithm) to automatically '
24 'plot an efficient path between two points, in the presence of '
25 'obstacles. Adapted from code by [Brian Gringstead]'
26 '(http://www.briangrinstead.com/blog/astar-search-algorithm-in-'
27 'javascript).',
28 'audio-beat-detection':
29 'This benchmark performs [beat detection]'
30 '(http://en.wikipedia.org/wiki/Beat_detection) on an Audio sample '
31 'using [code](http://beatdetektor.svn.sourceforge.net/viewvc'
32 '/beatdetektor/trunk/core/js/beatdetektor.js?revision=18&view=markup) '
33 'from [BeatDetektor](http://www.cubicproductions.com/index.php'
34 '?option=com_content&view=article&id=67&Itemid=82) and '
35 '[DSP.js](http://github.com/corbanbrook/dsp.js/).',
36 'audio-dft':
37 'This benchmark performs a [Discrete Fourier Transform]'
38 '(http://en.wikipedia.org/wiki/Discrete_Fourier_transform) on an '
39 'Audio sample using code from [DSP.js]'
40 '(http://github.com/corbanbrook/dsp.js).',
41 'audio-fft':
42 'This benchmark performs a [Fast Fourier Transform]'
43 '(http://en.wikipedia.org/wiki/Fast_Fourier_transform) on an Audio '
44 'sample using code from [DSP.js]'
45 '(http://github.com/corbanbrook/dsp.js/).',
46 'audio-oscillator':
47 'This benchmark generates a soundwave using code from [DSP.js]'
48 '(http://github.com/corbanbrook/dsp.js/).',
49 'imaging-darkroom':
50 'This benchmark performs a variety of photo manipulations such as '
51 'Fill, Brightness, Contrast, Saturation, and Temperature.',
52 'imaging-desaturate':
53 'This benchmark [desaturates]'
54 '(http://en.wikipedia.org/wiki/Colorfulness) a photo using code from '
55 '[Pixastic](http://www.pixastic.com/).',
56 'imaging-gaussian-blur':
57 'This benchmark performs a [Gaussian blur]'
58 '(http://en.wikipedia.org/wiki/Gaussian_blur) on a photo.',
59 'json-parse-financial':
60 'This benchmark parses [JSON](http://www.json.org) records.',
61 'json-stringify-tinderbox':
62 'This benchmark serializes [Tinderbox]'
63 '(http://tests.themasta.com/tinderboxpushlog/?tree=Firefox) build '
64 'data to [JSON](http://www.json.org).',
68 def _Mean(l):
69 return float(sum(l)) / len(l) if len(l) > 0 else 0.0
72 class _KrakenMeasurement(page_test.PageTest):
73 def __init__(self):
74 super(_KrakenMeasurement, self).__init__()
75 self._power_metric = None
77 def CustomizeBrowserOptions(self, options):
78 power.PowerMetric.CustomizeBrowserOptions(options)
80 def WillStartBrowser(self, platform):
81 self._power_metric = power.PowerMetric(platform)
83 def DidNavigateToPage(self, page, tab):
84 self._power_metric.Start(page, tab)
86 def ValidateAndMeasurePage(self, page, tab, results):
87 tab.WaitForJavaScriptExpression(
88 'document.title.indexOf("Results") != -1', 700)
89 tab.WaitForDocumentReadyStateToBeComplete()
91 self._power_metric.Stop(page, tab)
92 self._power_metric.AddResults(tab, results)
94 js_get_results = """
95 var formElement = document.getElementsByTagName("input")[0];
96 decodeURIComponent(formElement.value.split("?")[1]);
97 """
98 result_dict = eval(tab.EvaluateJavaScript(js_get_results))
99 total = 0
100 for key in result_dict:
101 if key == 'v':
102 continue
103 results.AddValue(list_of_scalar_values.ListOfScalarValues(
104 results.current_page, key, 'ms', result_dict[key], important=False,
105 description=DESCRIPTIONS.get(key)))
106 total += _Mean(result_dict[key])
108 # TODO(tonyg/nednguyen): This measurement shouldn't calculate Total. The
109 # results system should do that for us.
110 results.AddValue(scalar.ScalarValue(
111 results.current_page, 'Total', 'ms', total,
112 description='Total of the means of the results for each type '
113 'of benchmark in [Mozilla\'s Kraken JavaScript benchmark]'
114 '(http://krakenbenchmark.mozilla.org/)'))
117 class Kraken(perf_benchmark.PerfBenchmark):
118 """Mozilla's Kraken JavaScript benchmark.
120 http://krakenbenchmark.mozilla.org/
122 test = _KrakenMeasurement
124 @classmethod
125 def Name(cls):
126 return 'kraken'
128 def CreateStorySet(self, options):
129 ps = story.StorySet(
130 archive_data_file='../page_sets/data/kraken.json',
131 base_dir=os.path.dirname(os.path.abspath(__file__)),
132 cloud_storage_bucket=story.PARTNER_BUCKET)
133 ps.AddStory(page_module.Page(
134 'http://krakenbenchmark.mozilla.org/kraken-1.1/driver.html',
135 ps, ps.base_dir))
136 return ps