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> 7 var sandbox = document.getElementById('sandbox'); 8 var observing = false; 9 for (var i = 0; i < 1000; ++i) 10 sandbox.appendChild(document.createElement('div')); 11 var html = sandbox.innerHTML; 12 13 var observer = new WebKitMutationObserver(listener); 14 var tickledSpan = document.createElement('span'); 15 observer.observe(tickledSpan, {attributes: true}); 16 17 function resetState() { 18 window.start = null; 19 window.numRuns = 25; 20 window.times = []; 21 } 22 23 function runAgain() { 24 tickledSpan.setAttribute('data-foo', numRuns); 25 } 26 27 function 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 51 resetState(); 52 PerfTestRunner.log('Running ' + numRuns + ' times without observation'); 53 window.addEventListener('load', runAgain); 54 </script> 55 </body> 56