Skip to content

Instantly share code, notes, and snippets.

@zzzbra
Created February 18, 2015 03:22
Show Gist options
  • Save zzzbra/23736c2857c994b5ac5b to your computer and use it in GitHub Desktop.
Save zzzbra/23736c2857c994b5ac5b to your computer and use it in GitHub Desktop.
function SpeedTest(testImplement, testParams, repetitions){
this.testImplement = testImplement;
this.testParams = testParams;
this.repetitions = repetitions || 10000;
this.average = 0;
}
SpeedTest.prototype = {
startTest: function(){
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment