• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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>
7var sandbox = document.getElementById('sandbox');
8var node = sandbox;
9for (var i = 0; i < 200; ++i)
10    node = node.appendChild(document.createElement('div'));
11var observing = false;
12
13var observer = new WebKitMutationObserver(listener);
14var tickledSpan = document.createElement('span');
15observer.observe(tickledSpan, {attributes: true});
16
17function resetState() {
18    window.start = null;
19    window.numRuns = 25;
20    window.times = [];
21}
22
23function runAgain() {
24    tickledSpan.setAttribute('data-foo', numRuns);
25}
26
27function hideFromObservation(func) {
28    if (observing)
29        observer.disconnect();
30    func();
31    if (observing)
32        observer.observe(sandbox, {childList: true, subtree: true});
33}
34
35function listener(mutations) {
36    if (start) {
37        var time = Date.now() - start;
38        times.push(time);
39        PerfTestRunner.log(time);
40    }
41    if (numRuns-- >= 0) {
42        runAgain();
43        hideFromObservation(function() {
44            for (var i = 0; i < 50000; ++i)
45                node.appendChild(document.createElement('div'));
46        });
47        start = Date.now();
48        while (node.firstChild)
49            node.removeChild(node.firstChild);
50    } else {
51        PerfTestRunner.logStatistics(times);
52        if (!observing) {
53            observing = true;
54            resetState();
55            PerfTestRunner.log('\n------------\n');
56            PerfTestRunner.log('Running ' + numRuns + ' times with observation');
57            setTimeout(runAgain, 0);
58        }
59    }
60}
61
62resetState();
63PerfTestRunner.log('Running ' + numRuns + ' times without observation');
64window.addEventListener('load', runAgain);
65</script>
66</body>
67