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 node = sandbox; 9 for (var i = 0; i < 200; ++i) 10 node = node.appendChild(document.createElement('div')); 11 var observing = false; 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 hideFromObservation(func) { 28 if (observing) 29 observer.disconnect(); 30 func(); 31 if (observing) 32 observer.observe(sandbox, {childList: true, subtree: true}); 33 } 34 35 function listener(mutations) { 36 if (start) { 37 var time = Date.now() - start; 38 times.push(time); 39 PerfTestRunner.log(time); 40 } 41 if (numRuns-- >= 0) { 42 runAgain(); 43 hideFromObservation(function() { 44 for (var i = 0; i < 50000; ++i) 45 node.appendChild(document.createElement('div')); 46 }); 47 start = Date.now(); 48 while (node.firstChild) 49 node.removeChild(node.firstChild); 50 } else { 51 PerfTestRunner.logStatistics(times); 52 if (!observing) { 53 observing = true; 54 resetState(); 55 PerfTestRunner.log('\n------------\n'); 56 PerfTestRunner.log('Running ' + numRuns + ' times with observation'); 57 setTimeout(runAgain, 0); 58 } 59 } 60 } 61 62 resetState(); 63 PerfTestRunner.log('Running ' + numRuns + ' times without observation'); 64 window.addEventListener('load', runAgain); 65 </script> 66 </body> 67