5cb1de807531f65abb5304bd2b040966c664d25d
[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             for (var i = 0; i < checkboxes.length; i++)
134             app.toggle.call(checkboxes[i]);
135         }],
136         ['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
137             var app = contentWindow.app;
138             var deleteButtons = contentDocument.querySelectorAll('.destroy');
139             for (var i = 0; i < deleteButtons.length; i++)
140             app.destroy.call(deleteButtons[i]);
141         }],
142     ]
143 });
144
145 BenchmarkRunner.suite({
146     name: 'AngularJS/TodoMVC',
147     url: 'todomvc/architecture-examples/angularjs/index.html',
148     prepare: function (contentWindow, contentDocument) {
149         return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
150             element.focus();
151             return element;
152         });
153     },
154     tests: [
155         ['Adding' + numberOfItemsToAdd + 'Items', function (newTodo, contentWindow, contentDocument) {
156             var todomvc = contentWindow.todomvc;
157             var submitEvent = document.createEvent('Event');
158             submitEvent.initEvent('submit', true, true);
159             var inputEvent = document.createEvent('Event');
160             inputEvent.initEvent('input', true, true);
161             for (var i = 0; i < numberOfItemsToAdd; i++) {
162                 newTodo.value = 'Something to do ' + i;
163                 newTodo.dispatchEvent(inputEvent);
164                 newTodo.form.dispatchEvent(submitEvent);
165             }
166         }],
167         ['CompletingAllItems', function (newTodo, contentWindow, contentDocument) {
168             var checkboxes = contentDocument.querySelectorAll('.toggle');
169             for (var i = 0; i < checkboxes.length; i++)
170                 checkboxes[i].click();
171         }],
172         ['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
173             var deleteButtons = contentDocument.querySelectorAll('.destroy');
174             for (var i = 0; i < deleteButtons.length; i++)
175                 deleteButtons[i].click();
176         }],
177     ]
178 });
179
180 BenchmarkRunner.suite({
181     name: 'React/TodoMVC',
182     url: 'todomvc/labs/architecture-examples/react/index.html',
183     prepare: function (contentWindow, contentDocument) {
184         contentWindow.Utils.store = function () {}
185         return BenchmarkRunner.waitForElement('#new-todo').then(function (element) {
186             element.focus();
187             return element;
188         });
189     },
190     tests: [
191         ['Adding' + numberOfItemsToAdd + 'Items', function (newTodo, contentWindow, contentDocument) {
192             var todomvc = contentWindow.todomvc;
193             for (var i = 0; i < numberOfItemsToAdd; i++) {
194                 newTodo.value = 'Something to do ' + i;
195
196                 var keydownEvent = document.createEvent('Event');
197                 keydownEvent.initEvent('keydown', true, true);
198                 keydownEvent.which = 13; // VK_ENTER
199                 newTodo.dispatchEvent(keydownEvent);
200             }
201         }],
202         ['CompletingAllItems', function (newTodo, contentWindow, contentDocument) {
203             var checkboxes = contentDocument.querySelectorAll('.toggle');
204             for (var i = 0; i < checkboxes.length; i++)
205                 checkboxes[i].click();
206         }],
207         ['DeletingAllItems', function (newTodo, contentWindow, contentDocument) {
208             var deleteButtons = contentDocument.querySelectorAll('.destroy');
209             for (var i = 0; i < deleteButtons.length; i++)
210                 deleteButtons[i].click();
211         }],
212     ]
213 });
214
215 var actionCount = 50;
216 BenchmarkRunner.suite({
217     name: 'FlightJS/MailClient',
218     url: 'flightjs-example-app/index.html',
219     prepare: function (contentWindow, contentDocument) {
220         return BenchmarkRunner.waitForElement('.span8').then(function (element) {
221             element.focus();
222             return element;
223         });
224     },
225     tests: [
226         ['OpeningTabs' + actionCount + 'Times', function (newTodo, contentWindow, contentDocument) {
227             contentDocument.getElementById('inbox').click();
228             for (var i = 0; i < actionCount; i++) {
229                 contentDocument.getElementById('later').click();
230                 contentDocument.getElementById('sent').click();
231                 contentDocument.getElementById('trash').click();
232                 contentDocument.getElementById('inbox').click();
233             }
234         }],
235         ['MovingEmails' + actionCount + 'Times', function (newTodo, contentWindow, contentDocument) {
236             contentDocument.getElementById('inbox').click();
237             for (var i = 0; i < actionCount; i++) {
238                 contentDocument.getElementById('mail_2139').click();
239                 contentDocument.getElementById('move_mail').click();
240                 contentDocument.querySelector('#move_to_selector #later').click();
241                 contentDocument.getElementById('later').click();
242                 contentDocument.getElementById('mail_2139').click();
243                 contentDocument.getElementById('move_mail').click();
244                 contentDocument.querySelector('#move_to_selector #trash').click();
245                 contentDocument.getElementById('trash').click();
246                 contentDocument.getElementById('mail_2139').click();
247                 contentDocument.getElementById('move_mail').click();
248                 contentDocument.querySelector('#move_to_selector #inbox').click();
249                 contentDocument.getElementById('inbox').click();
250             }
251         }],
252         ['Sending' + actionCount + 'NewEmails', function (newTodo, contentWindow, contentDocument) {
253             for (var i = 0; i < actionCount; i++) {
254                 contentDocument.getElementById('new_mail').click();
255                 var subject = contentDocument.getElementById('compose_subject');
256                 var message = contentDocument.getElementById('compose_message');
257                 subject.focus();
258                 contentWindow.$(subject).trigger('keydown');
259                 contentDocument.execCommand('InsertText', false, 'Hello');
260                 message.focus();
261                 contentWindow.$(message).trigger('keydown');
262                 contentDocument.execCommand('InsertText', false, 'Hello,\n\nThis is a test message.\n\n- WebKitten');
263                 contentDocument.getElementById('send_composed').click();
264             }
265         }],
266     ]
267 });
268
269 </script>
270 </head>
271 <body>
272 </body>
273 </html>