DoYouEvenBench: Make it work on Internet Explorer 11 Release Preview
[WebKit-https.git] / PerformanceTests / DoYouEvenBench / benchmark.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>DoYouEvenBench</title>
5 <script src="benchmark.js"></script>
6 <script>
7
8 var numberOfItemsToAdd = 100;
9
10 BenchmarkRunner.suite({
11     name: 'VanillaJS/TodoMVC',
12     url: 'todomvc/vanilla-examples/vanillajs/index.html',
13     prepare: function (contentWindow, contentDocument) {
14         return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
15             element.focus();
16             return element;
17         });
18     },
19     tests: [
20         ['Adding' + numberOfItemsToAdd + 'Items', function (newTodo, contentWindow, contentDocument) {
21             var todoController = contentWindow.todo.controller;
22             for (var i = 0; i < numberOfItemsToAdd; i++) {
23                 newTodo.value = 'Something to do ' + i;
24                 todoController.addItem({keyCode: todoController.ENTER_KEY, target: newTodo});
25             }
26         }],
27         ['CompletingAllItems', function (newTodo, contentWindow, contentDocument) {
28             var checkboxes = contentDocument.querySelectorAll('.toggle');
29             for (var i = 0; i < checkboxes.length; i++)
30                 checkboxes[i].click();
31         }],
32         ['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
33             var deleteButtons = contentDocument.querySelectorAll('.destroy');
34             for (var i = 0; i < deleteButtons.length; i++)
35                 deleteButtons[i].click();
36         }],
37     ]
38 });
39
40 BenchmarkRunner.suite({
41     name: 'EmberJS/TodoMVC',
42     url: 'todomvc/architecture-examples/emberjs/index.html',
43     prepare: function (contentWindow, contentDocument) {
44         contentWindow.Todos.Store = contentWindow.DS.Store.extend({
45             revision: 12,
46             adapter: 'Todos.LSAdapter',
47             commit: function () { }
48         });
49
50         return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
51             element.focus();
52             return {
53                 views: contentWindow.Ember.View.views,
54                 emberRun: contentWindow.Ember.run,
55             }
56         });
57     },
58     tests: [
59         ['Adding' + numberOfItemsToAdd + 'Items', function (params) {
60             for (var i = 0; i < numberOfItemsToAdd; i++) {
61                 params.emberRun(function () { params.views["new-todo"].set('value', 'Something to do' + i); });
62                 params.emberRun(function () { params.views["new-todo"].insertNewline(document.createEvent('Event')); });
63             }
64         }],
65         ['CompletingAllItems', function (params, contentWindow, contentDocument) {
66             var checkboxes = contentDocument.querySelectorAll('.ember-checkbox');
67             for (var i = 0; i < checkboxes.length; i++) {
68                 var view = params.views[checkboxes[i].id];
69                 params.emberRun(function () { view.set('checked', true); });
70             }
71         }],
72         ['DeletingItems', function (params, contentWindow, contentDocument) {
73             var deleteButtons = contentDocument.querySelectorAll('.destroy');
74             for (var i = 0; i < deleteButtons.length; i++)
75                 params.emberRun(function () { deleteButtons[i].click(); });
76         }],
77     ]
78 });
79
80 BenchmarkRunner.suite({
81     name: 'BackboneJS/TodoMVC',
82     url: 'todomvc/architecture-examples/backbone/index.html',
83     prepare: function (contentWindow, contentDocument) {
84     contentWindow.Backbone.sync = function () {}
85         return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
86             element.focus();
87             return element;
88         });
89     },
90     tests: [
91         ['Adding' + numberOfItemsToAdd + 'Items', function (newTodo, contentWindow, contentDocument) {
92             var appView = contentWindow.appView;
93             var fakeEvent = {which: contentWindow.ENTER_KEY};
94             for (var i = 0; i < numberOfItemsToAdd; i++) {
95                 newTodo.value = 'Something to do ' + i;
96                 appView.createOnEnter(fakeEvent);
97             }
98         }],
99         ['CompletingAllItems', function (newTodo, contentWindow, contentDocument) {
100             var checkboxes = contentDocument.querySelectorAll('.toggle');
101             for (var i = 0; i < checkboxes.length; i++)
102                 checkboxes[i].click();
103         }],
104         ['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
105             var deleteButtons = contentDocument.querySelectorAll('.destroy');
106             for (var i = 0; i < deleteButtons.length; i++)
107                 deleteButtons[i].click();
108         }],
109     ]
110 });
111
112 BenchmarkRunner.suite({
113     name: 'jQuery/TodoMVC',
114     url: 'todomvc/architecture-examples/jquery/index.html',
115     prepare: function (contentWindow, contentDocument) {
116         return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
117             element.focus();
118             return element;
119         });
120     },
121     tests: [
122         ['Adding' + numberOfItemsToAdd + 'Items', function (newTodo, contentWindow, contentDocument) {
123             var app = contentWindow.app;
124             var fakeEvent = {which: app.ENTER_KEY};
125             for (var i = 0; i < numberOfItemsToAdd; i++) {
126                 newTodo.value = 'Something to do ' + i;
127                 app.create.call(newTodo, fakeEvent);
128             }
129         }],
130         ['CompletingAllItems', function (newTodo, contentWindow, contentDocument) {
131             var app = contentWindow.app;
132             var checkboxes = contentDocument.querySelectorAll('.toggle');
133             var $ = contentWindow.$;
134
135             itemIndexToId = new Array(checkboxes.length);
136             for (var i = 0; i < checkboxes.length; i++)
137                 itemIndexToId[i] = $(checkboxes[i]).closest('li').data('id');
138
139             app.getTodo = function (element, callback) {
140                 var self = this;
141                 var id = itemIndexToId[this.currentItemIndex];
142                 $.each(this.todos, function (j, val) {
143                     if (val.id === id) {
144                         callback.apply(self, arguments);
145                         return false;
146                     }
147                 });
148             }
149
150             for (var i = 0; i < checkboxes.length; i++) {
151                 app.currentItemIndex = i;
152                 app.toggle.call(checkboxes[i]);
153             }
154         }],
155         ['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
156             contentDocument.querySelector('#clear-completed').click();
157             var app = contentWindow.app;
158             var deleteButtons = contentDocument.querySelectorAll('.destroy');
159
160             for (var i = 0; i < deleteButtons.length; i++) {
161                 app.currentItemIndex = i;
162                 app.destroy.call(deleteButtons[i]);
163             }
164         }],
165     ]
166 });
167
168 BenchmarkRunner.suite({
169     name: 'AngularJS/TodoMVC',
170     url: 'todomvc/architecture-examples/angularjs/index.html',
171     prepare: function (contentWindow, contentDocument) {
172         return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
173             element.focus();
174             return element;
175         });
176     },
177     tests: [
178         ['Adding' + numberOfItemsToAdd + 'Items', function (newTodo, contentWindow, contentDocument) {
179             var todomvc = contentWindow.todomvc;
180             var submitEvent = document.createEvent('Event');
181             submitEvent.initEvent('submit', true, true);
182             var inputEvent = document.createEvent('Event');
183             inputEvent.initEvent('input', true, true);
184             for (var i = 0; i < numberOfItemsToAdd; i++) {
185                 newTodo.value = 'Something to do ' + i;
186                 newTodo.dispatchEvent(inputEvent);
187                 newTodo.form.dispatchEvent(submitEvent);
188             }
189         }],
190         ['CompletingAllItems', function (newTodo, contentWindow, contentDocument) {
191             var checkboxes = contentDocument.querySelectorAll('.toggle');
192             for (var i = 0; i < checkboxes.length; i++)
193                 checkboxes[i].click();
194         }],
195         ['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
196             var deleteButtons = contentDocument.querySelectorAll('.destroy');
197             for (var i = 0; i < deleteButtons.length; i++)
198                 deleteButtons[i].click();
199         }],
200     ]
201 });
202
203 BenchmarkRunner.suite({
204     name: 'React/TodoMVC',
205     url: 'todomvc/labs/architecture-examples/react/index.html',
206     prepare: function (contentWindow, contentDocument) {
207         contentWindow.Utils.store = function () {}
208         return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
209             element.focus();
210             return element;
211         });
212     },
213     tests: [
214         ['Adding' + numberOfItemsToAdd + 'Items', function (newTodo, contentWindow, contentDocument) {
215             var todomvc = contentWindow.todomvc;
216             for (var i = 0; i < numberOfItemsToAdd; i++) {
217                 newTodo.value = 'Something to do ' + i;
218
219                 var keydownEvent = document.createEvent('Event');
220                 keydownEvent.initEvent('keydown', true, true);
221                 keydownEvent.which = 13; // VK_ENTER
222                 newTodo.dispatchEvent(keydownEvent);
223             }
224         }],
225         ['CompletingAllItems', function (newTodo, contentWindow, contentDocument) {
226             var checkboxes = contentDocument.querySelectorAll('.toggle');
227             for (var i = 0; i < checkboxes.length; i++)
228                 checkboxes[i].click();
229         }],
230         ['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
231             var deleteButtons = contentDocument.querySelectorAll('.destroy');
232             for (var i = 0; i < deleteButtons.length; i++)
233                 deleteButtons[i].click();
234         }],
235     ]
236 });
237
238 var actionCount = 50;
239 BenchmarkRunner.suite({
240     name: 'FlightJS/MailClient',
241     url: 'flightjs-example-app/index.html',
242     prepare: function (contentWindow, contentDocument) {
243         return BenchmarkRunner.waitForElement('.span8').then(function (element) {
244             element.focus();
245             return element;
246         });
247     },
248     tests: [
249         ['OpeningTabs' + actionCount + 'Times', function (newTodo, contentWindow, contentDocument) {
250             contentDocument.getElementById('inbox').click();
251             for (var i = 0; i < actionCount; i++) {
252                 contentDocument.getElementById('later').click();
253                 contentDocument.getElementById('sent').click();
254                 contentDocument.getElementById('trash').click();
255                 contentDocument.getElementById('inbox').click();
256             }
257         }],
258         ['MovingEmails' + actionCount + 'Times', function (newTodo, contentWindow, contentDocument) {
259             contentDocument.getElementById('inbox').click();
260             for (var i = 0; i < actionCount; i++) {
261                 contentDocument.getElementById('mail_2139').click();
262                 contentDocument.getElementById('move_mail').click();
263                 contentDocument.querySelector('#move_to_selector #later').click();
264                 contentDocument.getElementById('later').click();
265                 contentDocument.getElementById('mail_2139').click();
266                 contentDocument.getElementById('move_mail').click();
267                 contentDocument.querySelector('#move_to_selector #trash').click();
268                 contentDocument.getElementById('trash').click();
269                 contentDocument.getElementById('mail_2139').click();
270                 contentDocument.getElementById('move_mail').click();
271                 contentDocument.querySelector('#move_to_selector #inbox').click();
272                 contentDocument.getElementById('inbox').click();
273             }
274         }],
275         ['Sending' + actionCount + 'NewEmails', function (newTodo, contentWindow, contentDocument) {
276             for (var i = 0; i < actionCount; i++) {
277                 contentDocument.getElementById('new_mail').click();
278                 contentDocument.getElementById('recipient_select').selectedIndex = 1;
279                 var subject = contentDocument.getElementById('compose_subject');
280                 var message = contentDocument.getElementById('compose_message');
281                 subject.focus();
282                 contentWindow.$(subject).trigger('keydown');
283                 contentWindow.$(subject).text('Hello');
284                 message.focus();
285                 contentWindow.$(message).trigger('keydown');
286                 contentWindow.$(message).text('Hello,\n\nThis is a test message.\n\n- WebKitten');
287                 contentDocument.getElementById('send_composed').click();
288             }
289         }],
290     ]
291 });
292
293 </script>
294 </head>
295 <body>
296 </body>
297 </html>