lib/bench.js
function bench(functions, options) {
  const funcs = assertFunctions(functions);
  const opts = assertOptions(options);
  const metrics = [];
  const totalRuns = funcs.length * opts.runs;
  let runCount = 0;

  for (let i = 0; i < funcs.length; i++) {
    const func = funcs[i];
    const totals = [0, 0];
    let max = 0;
    let min = Number.MAX_SAFE_INTEGER;

    for (let j = 0; j < opts.runs; j++) {
      const start = process.hrtime();
      func.fn.call(func.bind, func.params);
      const end = process.hrtime(start);

      totals[0] += end[0];
      totals[1] += end[1];

      const ns = (end[0] * NS_PER_SEC) + end[1];
      if (ns > max) max = ns;
      if (ns < min) min = ns;

      updateStatus(++runCount, totalRuns, opts.stream);
    }

    const whole = (totals[0] / opts.runs) * NS_PER_SEC;
    const partial = totals[1] / opts.runs;
    const avg = Math.ceil(whole + partial);

    metrics.push({
      avg,
      label: func.label,
      max,
      min,
    });
  }

  opts.report(opts.stream, metrics, opts.thresholds);
  checkThresholds(metrics, opts.thresholds);

  return metrics;
}
function bench(functions, options) {
  const funcs = assertFunctions(functions);
  const opts = assertOptions(options);
  const metrics = [];
  const totalRuns = funcs.length * opts.runs;
  let runCount = 0;

  for (let i = 0; i < funcs.length; i++) {
    const func = funcs[i];
    const totals = [0, 0];
    let max = 0;
    let min = Number.MAX_SAFE_INTEGER;

    for (let j = 0; j < opts.runs; j++) {
      const start = process.hrtime();
      func.fn.call(func.bind, func.params);
      const end = process.hrtime(start);

      totals[0] += end[0];
      totals[1] += end[1];

      const ns = (end[0] * NS_PER_SEC) + end[1];
      if (ns > max) max = ns;
      if (ns < min) min = ns;

      updateStatus(++runCount, totalRuns, opts.stream);
    }

    const whole = (totals[0] / opts.runs) * NS_PER_SEC;
    const partial = totals[1] / opts.runs;
    const avg = Math.ceil(whole + partial);

    metrics.push({
      avg,
      label: func.label,
      max,
      min,
    });
  }

  opts.report(opts.stream, metrics, opts.thresholds);
  checkThresholds(metrics, opts.thresholds);

  return metrics;
}
function bench ( functions , options ) { const funcs = assertFunctions ( functions ) ; const opts = assertOptions ( options ) ; const metrics = [ ] ; const totalRuns = funcs . length * opts . runs ; let runCount = 0 ; for ( let i = 0 ; i < funcs . length ; i ++ ) { const func = funcs [ i ] ; const totals = [ 0 , 0 ] ; let max = 0 ; let min = Number . MAX_SAFE_INTEGER ; for ( let j = 0 ; j < opts . runs ; j ++ ) { const start = process . hrtime ( ) ; func . fn . call ( func . bind , func . params ) ; const end = process . hrtime ( start ) ; totals [ 0 ] += end [ 0 ] ; totals [ 1 ] += end [ 1 ] ; const ns = ( end [ 0 ] * NS_PER_SEC ) + end [ 1 ] ; if ( ns > max ) max = ns ; if ( ns < min ) min = ns ; updateStatus ( ++ runCount , totalRuns , opts . stream ) ; } const whole = ( totals [ 0 ] / opts . runs ) * NS_PER_SEC ; const partial = totals [ 1 ] / opts . runs ; const avg = Math . ceil ( whole + partial ) ; metrics . push ( { avg , label : func . label , max , min , } ) ; } opts . report ( opts . stream , metrics , opts . thresholds ) ; checkThresholds ( metrics , opts . thresholds ) ; return metrics ; }
BENCHMARKING  
Runs a benchmark analysis for a given array of functions, and generates a
report.

@param {(function|FunctionConfiguration)[]} functions
@param {BenchOptions} options

@returns {FunctionMetrics[]}
BENCHMARKING Runs a benchmark analysis for a given array of functions and generates a report .