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