How to add tuning and disabling for each test in benchmark.js file

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);
+4
source share
1 answer

I am also new to tests and hope that I can answer correctly.

http://monsur.hossa.in/2012/12/11/benchmarkjs.html

If you read the above article, you will find out that the reference analysis will go to the stage of analysis and sampling.

It will run several iterations (ie, a “test loop”) that setText did during the sampling phase without calling setupor teardown.

, , - , , . ,

, ; Benchmark (vs ). ,

.on('complete', function(event) {
    //will log out the array of benchmark.suite, you can get it from each benchmark suite.
    //e.g event.currentTarget[0].hz which retrieve the operation/s. for the first one.
    console.log(event.currentTarget);
    //equivalent of above; event.currentTarget===this; both are Benchmark.suite.
    console.log(this); 
})
+3

All Articles