Skip to content

Instantly share code, notes, and snippets.

@cho45
Created January 24, 2009 21:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cho45/51564 to your computer and use it in GitHub Desktop.
Save cho45/51564 to your computer and use it in GitHub Desktop.
var orig_setTimeout = window.setTimeout;
window.setTimeout = function (fun, wait) {
if (wait < 15) {
orig_setTimeout(fun, wait);
} else {
var img = new Image();
img.onload = img.onerror = function () {
fun();
};
img.src = "data:,foo";
}
};
setTimeout(function () {
alert(navigator.userAgent);
document.body.addEventListener("click", function () { alert('click') }, false);
var prevTime = new Date().getTime();
var results = [];
setTimeout(function () {
var now = new Date().getTime();
results.push(now - prevTime);
if (results.length < 500) {
prevTime = new Date().getTime();
setTimeout(arguments.callee, 0);
} else {
document.body.appendChild(document.createTextNode(results.join(" ")));
var avg, sum = 0;
for (var i = 0; i < results.length; i++) {
sum += results[i];
}
avg = sum / results.length;
results.sort();
var min = results[0];
var max = results[results.length - 1];
document.body.appendChild(document.createTextNode(" avg:" + avg + " min:" + min + " max:" + max));
}
}, 0);
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment