adamk@chromium.org | cd510a2 | 2011-11-10 18:39:39 +0000 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <body> |
| 3 | <pre id="log"></pre> |
abarth@webkit.org | 49d2a48 | 2012-01-19 23:38:29 +0000 | [diff] [blame] | 4 | <script src="../resources/runner.js"></script> |
adamk@chromium.org | cd510a2 | 2011-11-10 18:39:39 +0000 | [diff] [blame] | 5 | <div id="sandbox" style="display:none"></div> |
| 6 | <script> |
| 7 | var sandbox = document.getElementById('sandbox'); |
| 8 | var observing = false; |
| 9 | |
| 10 | var observer = new WebKitMutationObserver(listener); |
| 11 | var tickledSpan = document.createElement('span'); |
| 12 | observer.observe(tickledSpan, {attributes: true}); |
| 13 | |
| 14 | function resetState() { |
| 15 | window.start = null; |
| 16 | window.numRuns = 25; |
| 17 | window.times = []; |
| 18 | } |
| 19 | |
| 20 | function runAgain() { |
| 21 | tickledSpan.setAttribute('data-foo', numRuns); |
| 22 | } |
| 23 | |
| 24 | function hideFromObservation(func) { |
| 25 | if (observing) |
| 26 | observer.disconnect() |
| 27 | func(); |
| 28 | if (observing) |
| 29 | observer.observe(sandbox, {childList: true}); |
| 30 | } |
| 31 | |
| 32 | function listener(mutations) { |
| 33 | if (start) { |
| 34 | var time = Date.now() - start; |
| 35 | times.push(time); |
rniwa@webkit.org | e0cd0a9 | 2012-01-31 20:05:37 +0000 | [diff] [blame] | 36 | PerfTestRunner.log(time); |
adamk@chromium.org | cd510a2 | 2011-11-10 18:39:39 +0000 | [diff] [blame] | 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 { |
rniwa@webkit.org | e0cd0a9 | 2012-01-31 20:05:37 +0000 | [diff] [blame] | 48 | PerfTestRunner.logStatistics(times); |
adamk@chromium.org | cd510a2 | 2011-11-10 18:39:39 +0000 | [diff] [blame] | 49 | if (!observing) { |
| 50 | observer.observe(sandbox, {childList: true}); |
| 51 | observing = true; |
| 52 | resetState(); |
rniwa@webkit.org | e0cd0a9 | 2012-01-31 20:05:37 +0000 | [diff] [blame] | 53 | PerfTestRunner.log('\n------------\n'); |
| 54 | PerfTestRunner.log('Running ' + numRuns + ' times with observation'); |
adamk@chromium.org | cd510a2 | 2011-11-10 18:39:39 +0000 | [diff] [blame] | 55 | setTimeout(runAgain, 0); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | resetState(); |
rniwa@webkit.org | e0cd0a9 | 2012-01-31 20:05:37 +0000 | [diff] [blame] | 61 | PerfTestRunner.log('Running ' + numRuns + ' times without observation'); |
adamk@chromium.org | cd510a2 | 2011-11-10 18:39:39 +0000 | [diff] [blame] | 62 | window.addEventListener('load', runAgain); |
| 63 | </script> |
| 64 | </body> |