I am trying to execute a sample performance benchmark using Benchmark.js. Here is what I have wrote:
var Benchmark = require('benchmark');
var arr = []
benchmark = new Benchmark('testPerf',function(){
arr.push(1000);
},
{
delay: 0,
initCount: 1,
minSamples: 1000,
onComplete : function(){ console.log(this);},
onCycle: function(){}
});
benchmark.run();
Now like we do in JUnitBenchmarks:
@BenchmarkOptions(clock = Clock.NANO_TIME, callgc = true, benchmarkRounds = 10, warmupRounds = 1)
Here also I want to declare benchmarkRounds
and warmupRounds
count in benchmarkjs. I think warmupRounds
maps to initCount
? And how to set exact number of cycles/benchmark iteration?
Or if we have some other good JavaScript library that can handle it would work too.
Using fixed iteration counts in JavaScript benchmarks is risky: we might get zero-time results eventually, as browsers become faster.
Benchmark.js does not allow setting the number of rounds/iterations in advance. Instead it runs tests over and over again until results can be considered reasonably accurate. You should check out the code reading by Monsur Hossain. Some highlights from the article:
Benchmark.prototype.cycles
.Benchmark.prototype.stats.sample
is an array of results from each cycle during sampling.Benchmark.prototype.count
is the number of iterations during sampling.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With