Created
September 23, 2014 14:44
-
-
Save toboqus/b9409f73d87ec8263763 to your computer and use it in GitHub Desktop.
Performance testing JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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