Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(648)

Side by Side Diff: lib/html/benchmarks/dromaeo/Dromaeo.dart

Issue 9950103: Remove obsolete version of dromaeo (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/html/benchmarks/common/common.lib ('k') | lib/html/benchmarks/dromaeo/Suites.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 class SuiteController {
2 final SuiteDescription _suiteDescription;
3 final IFrameElement _suiteIframe;
4
5 DivElement _element;
6 double _meanProduct;
7 int _nTests;
8
9 SuiteController(this._suiteDescription, this._suiteIframe)
10 : _meanProduct = 1.0,
11 _nTests = 0 {
12 _make();
13 _init();
14 }
15
16 start() {
17 _suiteIframe.contentWindow.dynamic.postMessage('start', '*');
18 }
19
20 update(String testName, num mean, num error, double percent) {
21 _meanProduct *= mean;
22 _nTests++;
23
24 final meanAsString = mean.toStringAsFixed(2);
25 final errorAsString = error.toStringAsFixed(2);
26 final Element progressDisplay = _element.nextNode.nextNode;
27 progressDisplay.innerHTML +=
28 '<li><b>${testName}:</b>' +
29 '${meanAsString}<small> runs/s &#177;${errorAsString}%<small></li>';
30 _updateTestPos(percent);
31 }
32
33 _make() {
34 _element = _createDiv('test');
35 // TODO(antonm): add an onclick functionality.
36 _updateTestPos();
37 }
38
39 _updateTestPos([double percent = 1.0]) {
40 String suiteName = _suiteDescription.name;
41 final done = percent >= 100.0;
42 String info = '';
43 if (done) {
44 final parent = _element.parent;
45 parent.attributes['class'] = parent.attributes['class'] + ' done';
46 final mean = Math.pow(_meanProduct, 1.0 / _nTests).toStringAsFixed(2);
47 info = '<span>${mean} runs/s</span>';
48 }
49 _element.innerHTML =
50 '<b>${suiteName}:</b>' +
51 '<div class="bar"><div style="width:${percent}%;">${info}</div></div>';
52 }
53
54 _init() {
55 final div = _createDiv('result-item');
56 div.nodes.add(_element);
57 final description = _suiteDescription.description;
58 final originUrl = _suiteDescription.origin.url;
59 final testUrl = 'tests/' + _suiteDescription.file;
60 div.innerHTML +=
61 '<p>${description}<br/><a href="${originUrl}">Origin</a>' +
62 ', <a href="${testUrl}">Source</a>' +
63 '<ol class="results"></ol>';
64 // Reread the element, as the previous wrapper get disconnected thanks
65 // to .innerHTML update above.
66 _element = div.nodes.first;
67
68 document.query('#main').nodes.add(div);
69 }
70
71 DivElement _createDiv(String clazz) {
72 final div = new Element.tag('div');
73 div.attributes['class'] = clazz;
74 return div;
75 }
76 }
77
78 class Dromaeo {
79 final Array<SuiteController> _suiteControllers;
80 Function _handler;
81
82 Dromaeo()
83 : _suiteControllers = new Array<SuiteController>(),
84 _handler = _createHandler()
85 {
86 window.on.message.add(
87 (MessageEvent event) {
88 try {
89 final response = JSON.parse(event.data);
90 _handler = _handler(response['command'], response['data']);
91 } catch (final e, final stacktrace) {
92 window.alert('Exception: ${e}: ${stacktrace}');
93 }
94 }
95 );
96 }
97
98 run() {
99 // TODO(antonm): create Re-run tests href.
100 document.query('#overview').elements.first.innerHTML = 'DOM Core Tests';
101 _css(document.query('#tests'), 'display', 'none');
102 for (SuiteDescription suite in Suites.SUITE_DESCRIPTIONS) {
103 final iframe = new Element.tag('iframe');
104 _css(iframe, 'height', '1px');
105 _css(iframe, 'width', '1px');
106 iframe.src = 'tests/' + suite.file;
107 document.body.nodes.add(iframe);
108
109 _suiteControllers.add(new SuiteController(suite, iframe));
110 }
111 }
112
113 static final double _SECS_PER_TEST = 5.0;
114
115 Function _createHandler() {
116 int suitesLoaded = 0;
117 int totalTests = 0;
118 int currentSuite;
119 double totalTimeSecs, estimatedTimeSecs;
120
121 // TODO(jat): Remove void type below. Bug 5269037.
122 void _updateTime() {
123 final mins = (estimatedTimeSecs / 60).floor().toInt();
124 final secs = (estimatedTimeSecs - mins * 60).round().toInt();
125 final secsAsString = (secs < 10 ? '0' : '') + secs;
126 document.query('#left').innerHTML = '${mins}:${secsAsString}';
127
128 final elapsed = totalTimeSecs - estimatedTimeSecs;
129 final percent = (100 * elapsed / totalTimeSecs).toStringAsFixed(2);
130 _css(document.query('#timebar'), 'width', '${percent}%');
131 }
132
133 Function loading, running, done;
134
135 loading = (String command, var data) {
136 assert(command == 'inited');
137 suitesLoaded++;
138 totalTests += data['nTests'];
139 if (suitesLoaded == _suitesTotal) {
140 totalTimeSecs = estimatedTimeSecs = _SECS_PER_TEST * totalTests;
141 _updateTime();
142 currentSuite = 0;
143 _suiteControllers[currentSuite].start();
144 return running;
145 }
146
147 return loading;
148 };
149
150 running = (String command, var data) {
151 switch (command) {
152 case 'result':
153 final testName = data['testName'];
154 final mean = data['mean'];
155 final error = data['error'];
156 final percent = data['percent'];
157 _suiteControllers[currentSuite].update(testName, mean, error, percent) ;
158 estimatedTimeSecs -= _SECS_PER_TEST;
159 _updateTime();
160 return running;
161
162 case 'over':
163 currentSuite++;
164 if (currentSuite < _suitesTotal) {
165 _suiteControllers[currentSuite].start();
166 return running;
167 }
168 document.body.attributes['class'] = 'alldone';
169 return done;
170
171 default:
172 throw 'Unknown command ${command} [${data}]';
173 }
174 };
175
176 done = (String command, var data) {
177 };
178
179 return loading;
180 }
181
182 _css(Element element, String property, String value) {
183 // TODO(antonm): remove the last argument when CallWithDefaultValue
184 // is implemented.
185 element.style.setProperty(property, value, '');
186 }
187
188 int get _suitesTotal() {
189 return _suiteControllers.length;
190 }
191 }
192
193 class Main {
194 static main() {
195 window.on.load.add((Event evt) => new Dromaeo().run());
196 }
197 }
OLDNEW
« no previous file with comments | « lib/html/benchmarks/common/common.lib ('k') | lib/html/benchmarks/dromaeo/Suites.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698