Skip to content

Instantly share code, notes, and snippets.

@toboqus
Created September 23, 2014 14:44
Show Gist options
  • Save toboqus/b9409f73d87ec8263763 to your computer and use it in GitHub Desktop.
Save toboqus/b9409f73d87ec8263763 to your computer and use it in GitHub Desktop.
Performance testing JS
(function(global){
var testFunc = function testFunc(func){
var start = new Date();
func();
return new Date() - start;
},
speedTest = function speedTest(name, func){
var numOfTimes = 1000,
times = 0;
for(var i = 0; i < numOfTimes; i++){
times = times+testFunc(func);
}
console.log(name+': '+(times/numOfTimes)+'ms average over '+numOfTimes+' iterations');
};
global.speedTest = speedTest;
})(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment