• 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 observing = false;
9for (var i = 0; i < 1000; ++i)
10    sandbox.appendChild(document.createElement('div'));
11var html = sandbox.innerHTML;
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 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        start = Date.now();
36        for (var i = 0; i < 100; ++i)
37            sandbox.innerHTML = html;
38    } else {
39        PerfTestRunner.logStatistics(times);
40        if (!observing) {
41            observer.observe(sandbox, {childList: true});
42            observing = true;
43            resetState();
44            PerfTestRunner.log('\n------------\n');
45            PerfTestRunner.log('Running ' + numRuns + ' times with observation');
46            setTimeout(runAgain, 0);
47        }
48    }
49}
50
51resetState();
52PerfTestRunner.log('Running ' + numRuns + ' times without observation');
53window.addEventListener('load', runAgain);
54</script>
55</body>
56