[Performance test] Add a micro benchmark for div.firstChild getter
[WebKit-https.git] / PerformanceTests / Bindings / dom-attributes.html
1 <!DOCTYPE html>
2 <body>
3 <script src="../resources/runner.js"></script>
4 <script>
5
6 var getterRepeat = 1500000;
7 var setterRepeat = 250000;
8
9 var times = {};
10
11 PerfTestRunner.run(function() {
12     var tests = [{name: 'HTMLElement.id',
13                   func: function() {
14                             var div = document.createElement("div");
15                             for (var i = 0; i < getterRepeat; i++)
16                                 div.id;
17                         }
18                  },
19                  {name: 'HTMLElement.title',
20                   func: function() {
21                             var div = document.createElement("div");
22                             for (var i = 0; i < getterRepeat; i++)
23                                 div.title;
24                         }
25                  },
26                  {name: 'HTMLElement.lang',
27                   func: function() {
28                             var div = document.createElement("div");
29                             for (var i = 0; i < getterRepeat; i++)
30                                 div.lang;
31                         }
32                  },
33                  {name: 'HTMLElement.dir',
34                   func: function() {
35                             var div = document.createElement("div");
36                             for (var i = 0; i < getterRepeat; i++)
37                                 div.dir;
38                         }
39                  },
40                  {name: 'HTMLElement.className',
41                   func: function() {
42                             var div = document.createElement("div");
43                             for (var i = 0; i < getterRepeat; i++)
44                                 div.className;
45                         }
46                  },
47                  {name: 'HTMLElement.classList',
48                   func: function() {
49                             var div = document.createElement("div");
50                             for (var i = 0; i < getterRepeat; i++)
51                                 div.classList;
52                         }
53                  },
54                  {name: 'HTMLElement.tabIndex',
55                   func: function() {
56                             var div = document.createElement("div");
57                             for (var i = 0; i < getterRepeat; i++)
58                                 div.tabIndex;
59                         }
60                  },
61                  {name: 'HTMLElement.draggable',
62                   func: function() {
63                             var div = document.createElement("div");
64                             for (var i = 0; i < getterRepeat; i++)
65                                 div.draggable;
66                         }
67                  },
68                  {name: 'HTMLElement.webkitdropzone',
69                   func: function() {
70                             var div = document.createElement("div");
71                             for (var i = 0; i < getterRepeat; i++)
72                                 div.webkitdropzone;
73                         }
74                  },
75                  {name: 'HTMLElement.hidden',
76                   func: function() {
77                             var div = document.createElement("div");
78                             for (var i = 0; i < getterRepeat; i++)
79                                 div.hidden;
80                         }
81                  },
82                  {name: 'HTMLElement.accessKey',
83                   func: function() {
84                             var div = document.createElement("div");
85                             for (var i = 0; i < getterRepeat; i++)
86                                 div.accessKey;
87                         }
88                  },
89                  {name: 'HTMLElement.children',
90                   func: function() {
91                             var div = document.createElement("div");
92                             for (var i = 0; i < getterRepeat; i++)
93                                 div.children;
94                         }
95                  },
96                  {name: 'HTMLElement.isContentEditable',
97                   func: function() {
98                             var div = document.createElement("div");
99                             for (var i = 0; i < getterRepeat; i++)
100                                 div.isContentEditable;
101                         }
102                  },
103                  {name: 'HTMLElement.spellcheck',
104                   func: function() {
105                             var div = document.createElement("div");
106                             for (var i = 0; i < getterRepeat; i++)
107                                 div.spellcheck;
108                         }
109                  },
110                  {name: 'HTMLElement.innerHTML',
111                   func: function() {
112                             var div = document.createElement("div");
113                             for (var i = 0; i < getterRepeat; i++)
114                                 div.innerHTML;
115                         }
116                  },
117                  {name: 'HTMLElement.innerText',
118                   func: function() {
119                             var div = document.createElement("div");
120                             for (var i = 0; i < getterRepeat; i++)
121                                 div.innerText;
122                         }
123                  },
124                  {name: 'HTMLElement.outerHTML',
125                   func: function() {
126                             var div = document.createElement("div");
127                             for (var i = 0; i < getterRepeat; i++)
128                                 div.outerHTML;
129                         }
130                  },
131                  {name: 'HTMLElement.outerText',
132                   func: function() {
133                             var div = document.createElement("div");
134                             for (var i = 0; i < getterRepeat; i++)
135                                 div.outerText;
136                         }
137                  },
138                  {name: 'HTMLElement.contentEditable',
139                   func: function() {
140                             var div = document.createElement("div");
141                             for (var i = 0; i < getterRepeat; i++)
142                                 div.contentEditable;
143                         }
144                  },
145                  {name: 'HTMLElement.id="foo"',
146                   func: function() {
147                             var div = document.createElement("div");
148                             for (var i = 0; i < setterRepeat; i++)
149                                 div.id = "foo";
150                         }
151                  },
152                  {name: 'HTMLElement.title="foo"',
153                   func: function() {
154                             var div = document.createElement("div");
155                             for (var i = 0; i < setterRepeat; i++)
156                                 div.title = "foo";
157                         }
158                  },
159                  {name: 'HTMLElement.lang="foo"',
160                   func: function() {
161                             var div = document.createElement("div");
162                             for (var i = 0; i < setterRepeat; i++)
163                                 div.lang = "foo";
164                         }
165                  },
166                  {name: 'HTMLElement.dir="foo"',
167                   func: function() {
168                             var div = document.createElement("div");
169                             for (var i = 0; i < setterRepeat; i++)
170                                 div.dir = "foo";
171                         }
172                  },
173                  {name: 'HTMLElement.className="foo"',
174                   func: function() {
175                             var div = document.createElement("div");
176                             for (var i = 0; i < setterRepeat; i++)
177                                 div.className = "foo";
178                         }
179                  },
180                  {name: 'HTMLElement.tabIndex="foo"',
181                   func: function() {
182                             var div = document.createElement("div");
183                             for (var i = 0; i < setterRepeat; i++)
184                                 div.tabIndex = "foo";
185                         }
186                  },
187                  {name: 'HTMLElement.draggable="foo"',
188                   func: function() {
189                             var div = document.createElement("div");
190                             for (var i = 0; i < setterRepeat; i++)
191                                 div.draggable = "foo";
192                         }
193                  },
194                  {name: 'HTMLElement.webkitdropzone="foo"',
195                   func: function() {
196                             var div = document.createElement("div");
197                             for (var i = 0; i < setterRepeat; i++)
198                                 div.webkitdropzone = "foo";
199                         }
200                  },
201                  {name: 'HTMLElement.hidden="foo"',
202                   func: function() {
203                             var div = document.createElement("div");
204                             for (var i = 0; i < setterRepeat; i++)
205                                 div.hidden = "foo";
206                         }
207                  },
208                  {name: 'HTMLElement.accessKey="foo"',
209                   func: function() {
210                             var div = document.createElement("div");
211                             for (var i = 0; i < setterRepeat; i++)
212                                 div.accessKey = "foo";
213                         }
214                  },
215                  {name: 'HTMLElement.spellcheck="foo"',
216                   func: function() {
217                             var div = document.createElement("div");
218                             for (var i = 0; i < setterRepeat; i++)
219                                 div.spellcheck = "foo";
220                         }
221                  },
222                  {name: 'HTMLElement.innerHTML="foo"',
223                   func: function() {
224                             var div = document.createElement("div");
225                             for (var i = 0; i < setterRepeat; i++)
226                                 div.innerHTML = "foo";
227                         }
228                  },
229                  {name: 'HTMLElement.innerText="foo"',
230                   func: function() {
231                             var div = document.createElement("div");
232                             for (var i = 0; i < setterRepeat; i++)
233                                 div.innerText = "foo";
234                         }
235                  },
236                  {name: 'Element.tagName',
237                   func: function() {
238                             var div = document.createElement("div");
239                             for (var i = 0; i < getterRepeat; i++)
240                                 div.tagName;
241                         }
242                  },
243                  {name: 'Element.style',
244                   func: function() {
245                             var div = document.createElement("div");
246                             for (var i = 0; i < getterRepeat; i++)
247                                 div.style;
248                         }
249                  },
250                  {name: 'Element.offsetLeft',
251                   func: function() {
252                             var div = document.createElement("div");
253                             for (var i = 0; i < getterRepeat; i++)
254                                 div.offsetLeft;
255                         }
256                  },
257                  {name: 'Element.clientLeft',
258                   func: function() {
259                             var div = document.createElement("div");
260                             for (var i = 0; i < getterRepeat; i++)
261                                 div.clientLeft;
262                         }
263                  },
264                  {name: 'Element.scrollLeft',
265                   func: function() {
266                             var div = document.createElement("div");
267                             for (var i = 0; i < getterRepeat; i++)
268                                 div.scrollLeft;
269                         }
270                  },
271                  {name: 'Element.dataset',
272                   func: function() {
273                             var div = document.createElement("div");
274                             for (var i = 0; i < getterRepeat; i++)
275                                 div.dataset;
276                         }
277                  },
278                  {name: 'Element.firstElementChild',
279                   func: function() {
280                             var div = document.createElement("div");
281                             for (var i = 0; i < getterRepeat; i++)
282                                 div.firstElementChild;
283                         }
284                  },
285                  {name: 'Element.lastElementChild',
286                   func: function() {
287                             var div = document.createElement("div");
288                             for (var i = 0; i < getterRepeat; i++)
289                                 div.lastElementChild;
290                         }
291                  },
292                  {name: 'Element.previousElementSibling',
293                   func: function() {
294                             var div = document.createElement("div");
295                             for (var i = 0; i < getterRepeat; i++)
296                                 div.previousElementSibling;
297                         }
298                  },
299                  {name: 'Element.nextElementSibling',
300                   func: function() {
301                             var div = document.createElement("div");
302                             for (var i = 0; i < getterRepeat; i++)
303                                 div.nextElementSibling;
304                         }
305                  },
306                  {name: 'Element.childElementCount',
307                   func: function() {
308                             var div = document.createElement("div");
309                             for (var i = 0; i < getterRepeat; i++)
310                                 div.childElementCount;
311                         }
312                  },
313                  {name: 'Element.onload',
314                   func: function() {
315                             var div = document.createElement("div");
316                             for (var i = 0; i < getterRepeat; i++)
317                                 div.onload;
318                         }
319                  },
320                  {name: 'Element.scrollLeft="foo"',
321                   func: function() {
322                             var div = document.createElement("div");
323                             for (var i = 0; i < setterRepeat; i++)
324                                 div.scrollLeft = "foo";
325                         }
326                  },
327                  {name: 'Element.onload="foo"',
328                   func: function() {
329                             var div = document.createElement("div");
330                             for (var i = 0; i < setterRepeat; i++)
331                                 div.onload = "foo";
332                         }
333                  },
334                  {name: 'Node.nodeName',
335                   func: function() {
336                             var div = document.createElement("div");
337                             for (var i = 0; i < getterRepeat; i++)
338                                 div.nodeName;
339                         }
340                  },
341                  {name: 'Node.nodeType',
342                   func: function() {
343                             var div = document.createElement("div");
344                             for (var i = 0; i < getterRepeat; i++)
345                                 div.nodeType;
346                         }
347                  },
348                  {name: 'Node.parentNode',
349                   func: function() {
350                             var div = document.createElement("div");
351                             for (var i = 0; i < getterRepeat; i++)
352                                 div.parentNode;
353                         }
354                  },
355                  {name: 'Node.childNodes',
356                   func: function() {
357                             var div = document.createElement("div");
358                             for (var i = 0; i < getterRepeat; i++)
359                                 div.childNodes;
360                         }
361                  },
362                  {name: 'Node.firstChild',
363                   func: function() {
364                             var div = document.createElement("div");
365                             for (var i = 0; i < getterRepeat; i++)
366                                 div.firstChild;
367                         }
368                  },
369                  {name: 'Node.lastChild',
370                   func: function() {
371                             var div = document.createElement("div");
372                             for (var i = 0; i < getterRepeat; i++)
373                                 div.lastChild;
374                         }
375                  },
376                  {name: 'Node.previousSibling',
377                   func: function() {
378                             var div = document.createElement("div");
379                             for (var i = 0; i < getterRepeat; i++)
380                                 div.previousSibling;
381                         }
382                  },
383                  {name: 'Node.nextSibling',
384                   func: function() {
385                             var div = document.createElement("div");
386                             for (var i = 0; i < getterRepeat; i++)
387                                 div.nextSibling;
388                         }
389                  },
390                  {name: 'Node.attributes',
391                   func: function() {
392                             var div = document.createElement("div");
393                             for (var i = 0; i < getterRepeat; i++)
394                                 div.attributes;
395                         }
396                  },
397                  {name: 'Node.ownerDocument',
398                   func: function() {
399                             var div = document.createElement("div");
400                             for (var i = 0; i < getterRepeat; i++)
401                                 div.ownerDocument;
402                         }
403                  },
404                  {name: 'Node.namespaceURI',
405                   func: function() {
406                             var div = document.createElement("div");
407                             for (var i = 0; i < getterRepeat; i++)
408                                 div.namespaceURI;
409                         }
410                  },
411                  {name: 'Node.localName',
412                   func: function() {
413                             var div = document.createElement("div");
414                             for (var i = 0; i < getterRepeat; i++)
415                                 div.localName;
416                         }
417                  },
418                  {name: 'Node.baseURI',
419                   func: function() {
420                             var div = document.createElement("div");
421                             for (var i = 0; i < getterRepeat; i++)
422                                 div.baseURI;
423                         }
424                  },
425                  {name: 'Node.parentElement',
426                   func: function() {
427                             var div = document.createElement("div");
428                             for (var i = 0; i < getterRepeat; i++)
429                                 div.parentElement;
430                         }
431                  },
432                  {name: 'Node.nodeValue',
433                   func: function() {
434                             var div = document.createElement("div");
435                             for (var i = 0; i < getterRepeat; i++)
436                                 div.nodeValue;
437                         }
438                  },
439                  {name: 'Node.prefix',
440                   func: function() {
441                             var div = document.createElement("div");
442                             for (var i = 0; i < getterRepeat; i++)
443                                 div.prefix;
444                         }
445                  },
446                  {name: 'Node.textContent',
447                   func: function() {
448                             var div = document.createElement("div");
449                             for (var i = 0; i < getterRepeat; i++)
450                                 div.textContent;
451                         }
452                  },
453                  {name: 'Node.nodeValue="foo"',
454                   func: function() {
455                             var div = document.createElement("div");
456                             for (var i = 0; i < setterRepeat; i++)
457                                 div.nodeValue = "foo";
458                         }
459                  },
460                  {name: 'Node.prefix="foo"',
461                   func: function() {
462                             var div = document.createElement("div");
463                             for (var i = 0; i < setterRepeat; i++)
464                                 div.prefix = "foo";
465                         }
466                  },
467                  {name: 'Node.textContent="foo"',
468                   func: function() {
469                             var div = document.createElement("div");
470                             for (var i = 0; i < setterRepeat; i++)
471                                 div.textContent = "foo";
472                         }
473                  },
474                 ];
475     runTests(tests);
476 }, 1, 5, onCompleted);
477
478 function runTests(tests) {
479     for (var i = 0; i < tests.length; i++) {
480         var start = Date.now();
481         (tests[i].func)();
482         if (times[tests[i].name] === undefined)
483             times[tests[i].name] = [];
484         times[tests[i].name].push(Date.now() - start);
485     }
486 }
487
488 function onCompleted() {
489     for (var name in times) {
490         var statistics = PerfTestRunner.computeStatistics(times[name]);
491         PerfTestRunner.info("[" + name + "] avg=" + statistics.mean.toFixed(2) + "ms, median=" + statistics.median.toFixed(2) + "ms, stdev=" + statistics.stdev.toFixed(2) + "ms, min=" + statistics.min + ", max=" + statistics.max);
492     }
493 }
494 </script>
495 </body>
496 </html>