| <!DOCTYPE html> |
| <body> |
| <pre id="log"></pre> |
| <script> |
| function log(text) { |
| document.getElementById("log").innerText += text + "\n"; |
| window.scrollTo(document.body.height); |
| } |
| |
| function loadFile(path) { |
| var xhr = new XMLHttpRequest(); |
| xhr.open("GET", path, false); |
| xhr.send(null); |
| return xhr.responseText; |
| } |
| |
| var spec = loadFile("resources/html5.html"); |
| |
| function parse(html) { |
| var iframe = document.createElement("iframe"); |
| iframe.src = "about:blank"; |
| iframe.style.display = "none"; |
| document.body.appendChild(iframe) |
| iframe.contentDocument.open(); |
| iframe.contentDocument.write(html); |
| iframe.contentDocument.close(); |
| document.body.removeChild(iframe) |
| } |
| |
| var runCount = 20; |
| var completedRuns = -1; // Discard the any runs < 0. |
| var times = []; |
| |
| function computeAverage(values) { |
| var sum = 0; |
| for (var i = 0; i < values.length; i++) |
| sum += values[i]; |
| return sum / values.length; |
| } |
| |
| function computeStdev(values) { |
| var average = computeAverage(values); |
| var sumOfSquaredDeviations = 0; |
| for (var i = 0; i < values.length; ++i) { |
| var deviation = values[i] - average; |
| sumOfSquaredDeviations += deviation * deviation; |
| } |
| return Math.sqrt(sumOfSquaredDeviations / values.length); |
| } |
| |
| function logStatistics(times) { |
| log(""); |
| log("avg " + computeAverage(times)); |
| log("stdev " + computeStdev(times)); |
| } |
| |
| function run() { |
| var start = new Date(); |
| for (var i = 0; i < 10; ++i) |
| parse(spec); |
| var time = new Date() - start; |
| completedRuns++; |
| if (completedRuns <= 0) { |
| log("Ignoring warm-up run (" + time + ")"); |
| } else { |
| times.push(time); |
| log(time); |
| } |
| if (completedRuns < runCount) { |
| window.setTimeout(run, 0); |
| } else { |
| logStatistics(times); |
| } |
| } |
| |
| log("Running " + runCount + " times"); |
| run(); |
| </script> |
| </body> |