Skip to content

Instantly share code, notes, and snippets.

@valdrinkoshi
Created January 13, 2017 02:20
Show Gist options
  • Save valdrinkoshi/ccf8ce4631e417c38143c8ef5b7eb5ad to your computer and use it in GitHub Desktop.
Save valdrinkoshi/ccf8ce4631e417c38143c8ef5b7eb5ad to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<body>
<button onclick="count = total">stop</button>
<pre id="out"></pre>
<script>
var count = 0;
var total = 20;
var times = [];
// Call this method in html-imports at the first line of the script:
// window.top.startTime()
window.startTime = function() {
times.push(new Date());
// console.time('html-imports');
};
// Call this method in html-imports when firing 'HTMLImportsLoaded':
// window.top.endTime()
window.endTime = function() {
// console.timeEnd('html-imports');
// Replace last with diff.
times.push(new Date() - times.pop());
};
function generateIframe() {
count++;
var iframe = document.createElement('iframe');
iframe.width = 500;
iframe.height = 500;
iframe.onload = function() {
iframe.contentWindow.HTMLImports.whenReady(function() {
setTimeout(function() {
// Log stats.
var sum = 0;
for (var i = 0; i < times.length; i++) {
sum += times[i];
}
var avg = sum / (times.length);
out.textContent += avg + '\n';
if (count < total) {
iframe.parentNode.removeChild(iframe);
setTimeout(generateIframe, 500);
}
}, 500);
});
};
iframe.src = 'index.html';
document.body.appendChild(iframe);
}
generateIframe();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment