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 elems = []; 12 for (var i = 0; i < 50000; ++i) 13 elems[i] = document.createElement('div'); 14 var observing = false; 15 16 var observer = new WebKitMutationObserver(listener); 17 var tickledSpan = document.createElement('span'); 18 observer.observe(tickledSpan, {attributes: true}); 19 20 function resetState() { 21 window.start = null; 22 window.numRuns = 25; 23 window.times = []; 24 } 25 26 function runAgain() { 27 tickledSpan.setAttribute('data-foo', numRuns); 28 } 29 30 function listener(mutations) { 31 if (start) { 32 var time = Date.now() - start; 33 times.push(time); 34 PerfTestRunner.log(time); 35 } 36 if (numRuns-- >= 0) { 37 runAgain(); 38 if (observing) 39 observer.disconnect() 40 node.innerHTML = ''; 41 if (observing) 42 observer.observe(sandbox, {childList: true, subtree: true}); 43 start = Date.now(); 44 for (var i = 0; i < elems.length; ++i) 45 node.appendChild(elems[i]); 46 } else { 47 PerfTestRunner.logStatistics(times); 48 if (!observing) { 49 observing = true; 50 resetState(); 51 PerfTestRunner.log('\n------------\n'); 52 PerfTestRunner.log('Running ' + numRuns + ' times with observation'); 53 setTimeout(runAgain, 0); 54 } 55 } 56 } 57 58 resetState(); 59 PerfTestRunner.log('Running ' + numRuns + ' times without observation'); 60 window.addEventListener('load', runAgain); 61 </script> 62 </body> 63