if (typeof(require) !== 'undefined') { var Benchmark = require('benchmark'); } var suite = new Benchmark.Suite; suite .add('function#A', function() { // Version A }) .add('function#B', function() { // Version B }) // add listeners .on('start', function() { console.log('Started'); }) .on('cycle', function(event) { console.log(String(event.target)); }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').pluck('name')); }) // run async .run({ 'async': true });