Skip to content

Instantly share code, notes, and snippets.

@szmeku
Created January 11, 2013 20:51
Show Gist options
  • Select an option

  • Save szmeku/4513863 to your computer and use it in GitHub Desktop.

Select an option

Save szmeku/4513863 to your computer and use it in GitHub Desktop.
Extends native 'performance' object with function that measure execution time
(function(w){
w.performance.measureTime = function(what, times){
var results = [];
for(var i=0; i<times; i++){
var start = window.performance.webkitNow();
what();
var end = window.performance.webkitNow();
results.push(end - start);
}
var sum = 0;
for(var i in results){ sum += results[i] }
return sum/results.length;
};
})(window)
// ======= Example of usage ==========
// executes console.log('dupa') 500 times and returns avarage execution time
performance.measureTime(function(){
console.log('dupa')
}, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment