class SpeedTest {
constructor (testFunction, testParams, iterations) {
this.testFunction = testFunction;
this.testParams = testParams;
this.iterations = iterations || 10000;
this.average = 0;
}
startTest() {
var beginTime, endTime, sumTimes = 0;
for (var i = 0, x = this.iterations; i < x; i++) {
beginTime= +new Date();
this.testFunction(...this.testParams);
endTime = +new Date();
sumTimes += endTime - beginTime;
}
this.average = sumTimes / this.iterations;
return console.log(["Average execution across ", this.iterations, ": ", this.average].join(''));
}
}
This class helps to tests code blocks and gets the average execution time.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.