blob: 182f28b3efd7d5b60a0bb79cbf7992e13c939172 [file] [log] [blame]
adamk@chromium.orgcd510a22011-11-10 18:39:39 +00001<!DOCTYPE html>
2<body>
3<pre id="log"></pre>
abarth@webkit.org49d2a482012-01-19 23:38:29 +00004<script src="../resources/runner.js"></script>
adamk@chromium.orgcd510a22011-11-10 18:39:39 +00005<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);
rniwa@webkit.orge0cd0a92012-01-31 20:05:37 +000036 PerfTestRunner.log(time);
adamk@chromium.orgcd510a22011-11-10 18:39:39 +000037 }
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 {
rniwa@webkit.orge0cd0a92012-01-31 20:05:37 +000048 PerfTestRunner.logStatistics(times);
adamk@chromium.orgcd510a22011-11-10 18:39:39 +000049 if (!observing) {
50 observer.observe(sandbox, {childList: true});
51 observing = true;
52 resetState();
rniwa@webkit.orge0cd0a92012-01-31 20:05:37 +000053 PerfTestRunner.log('\n------------\n');
54 PerfTestRunner.log('Running ' + numRuns + ' times with observation');
adamk@chromium.orgcd510a22011-11-10 18:39:39 +000055 setTimeout(runAgain, 0);
56 }
57 }
58}
59
60resetState();
rniwa@webkit.orge0cd0a92012-01-31 20:05:37 +000061PerfTestRunner.log('Running ' + numRuns + ' times without observation');
adamk@chromium.orgcd510a22011-11-10 18:39:39 +000062window.addEventListener('load', runAgain);
63</script>
64</body>