I am new to using benchmark.js, the documentation is bit jarring, and not able to find many examples, can anyone please confirm if my code is correct, sorry i cannot share the whole code( company policy).
consider setText(choice);
as some operation, and I want to compare various choices. (the function works fine independently, i have verified it). Though I am setting setup and teardown function, I am not sure if setting is correct, I want them to run before and after every single run of setText(choice);
using console.log
, I found that they run only once for every 200 times of setText(choice);
, I want them running everytime.
also, how do I retrive the ops/sec for each opeartion on completion of suite . You can find the my benchmark suite related code below.
var suite = new Benchmark.Suite;
suite.add('innerText', function() {
setText('innerText');
}, {'setup':setup,'teardown':teardown})
.add('innerHTML', function() {
setText('innerHTML');
}, {'setup':setup,'teardown':teardown})
.add('textContent', function() {
setText('textContent');
}, {'setup':setup,'teardown':teardown})
.on('cycle', function(event, bench) {
log(String(bench));
}).on('complete', function() {
log('Fastest is ' + JSON.stringify(this));
}).run(false);