How to use the benchmark function in benchmark

To help you get started, we’ve selected a few benchmark examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tylingsoft / dagre-layout / src / bench.js View on Github external
target.name,
      Benchmark.formatNumber(hz.toFixed(2)),
      rme.toFixed(2),
      samples)
    console.log(msg)
  }
  options.onError = function (bench) {
    console.error('    ' + bench.target.error)
  }
  options.setup = function () {
    this.count = Math.random() * 1000
    this.nextInt = function (range) {
      return Math.floor(this.count++ % range)
    }
  }
  new Benchmark(name, fn, options).run()
}
github parro-it / comws / bench / run.js View on Github external
function makeBench(fnToRun,name){
    return new Benchmark({
        defer: true,
        name: name,

        fn (deferred) {
            fnToRun().then((result)=>{
                if(result !== 4950){
                    console.error('bad result:' + result);
                    benchCoMws.abort();
                }
                deferred.resolve();
            }).catch(console.log);

        },

        onError(err) {
          console.error(err);
github jsdw / angu / src / index.bench.ts View on Github external
function benchmark(name: string, fn: () => void) {
    const bench = new Benchmark(name, fn)
    try {
        fn()
        bench
            .on('complete', function(event: any) {
                console.log(String(event.target))
            })
            .run()
    } catch(e) {
        console.log(`${name} threw an error: ${e}`)
    }
}