3a128b1909f7fafa27349bb393bf48f883f53229
[WebKit-https.git] / PerformanceTests / Mutation / append-child.html
1 <!DOCTYPE html>
2 <body>
3 <pre id="log"></pre>
4 <script src="../resources/runner.js"></script>
5 <div id="sandbox" style="display:none"></div>
6 <script>
7 var sandbox = document.getElementById('sandbox');
8 var observing = false;
9
10 var elems = [];
11 for (var i = 0; i < 50000; ++i)
12     elems[i] = document.createElement('div');
13 var observer = new WebKitMutationObserver(listener);
14 var tickledSpan = document.createElement('span');
15 observer.observe(tickledSpan, {attributes: true});
16
17 function resetState() {
18     window.start = null;
19     window.numRuns = 25;
20     window.times = [];
21 }
22
23 function runAgain() {
24     tickledSpan.setAttribute('data-foo', numRuns);
25 }
26
27 function listener(mutations) {
28     if (start) {
29         var time = Date.now() - start;
30         times.push(time);
31         PerfTestRunner.log(time);
32     }
33     if (numRuns-- >= 0) {
34         runAgain();
35         if (observing)
36             observer.disconnect()
37         sandbox.innerHTML = '';
38         if (observing)
39             observer.observe(sandbox, {childList: true});
40         start = Date.now();
41         for (var i = 0; i < elems.length; ++i)
42             sandbox.appendChild(elems[i]);
43     } else {
44         PerfTestRunner.logStatistics(times);
45         if (!observing) {
46             observing = true;
47             resetState();
48             PerfTestRunner.log('\n------------\n');
49             PerfTestRunner.log('Running ' + numRuns + ' times with observation');
50             setTimeout(runAgain, 0);
51         }
52     }
53 }
54
55 resetState();
56 PerfTestRunner.log('Running ' + numRuns + ' times without observation');
57 window.addEventListener('load', runAgain);
58 </script>
59 </body>