I am new to benchmark.js, the documentation is a bit annoying and cannot find many examples, can anyone confirm that my code is correct, sorry, I can’t use all the code (company policy).
consider setText(choice);how some operation, and I want to compare different options. (the function works fine independently, I checked it). Although I set the setup and break function, I'm not sure if the setup is correct, I want them to start before and after each runsetText(choice);
using console.log, I found that they only run once every 200 times setText(choice);, I want them to run every time.
Also, how can I get ops / sec for each version after dialing is complete. You can find the corresponding code associated with the reference set 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);
source
share