Skip to content

Instantly share code, notes, and snippets.

@carloscarvallo
Created November 21, 2016 19:04
Show Gist options
  • Save carloscarvallo/fd269dcb8f8307f78328cee469704229 to your computer and use it in GitHub Desktop.
Save carloscarvallo/fd269dcb8f8307f78328cee469704229 to your computer and use it in GitHub Desktop.
var SpeedTest = function(testImplement,testParams,repetitions) {
this.testImplement = testImplement;
this.testParams = testParams;
this.repetitions = repetitions || 10000;
this.average = 0;
};
SpeedTest.prototype = {
startTest: function() {
if (this.testImplement(this.testParams) === false) {
alert('Test failed with those parameters.');
return;
}
var beginTime, endTime, sumTimes = 0;
for (var i = 0, x = this.repetitions; i < x; i++) {
beginTime = +new Date();
this.testImplement(this.testParams);
endTime = +new Date();
sumTimes += endTime - beginTime;
}
this.average = sumTimes / this.repetitions;
return console.log('Average execution across ' + this.repetitions + ': ' + this.average);
}
};
// test
var list = ["como perro", "como esos crazys", "jodido pio"];
var iteration = function(list) {
for (var i = 0; i < list.length; i++) {
console.log(list[i])
}
}
var tester = new SpeedTest(iteration, list, 5000)
tester.startTest();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment