if (typeof(require) !== 'undefined') { var Benchmark = require('benchmark'); } var suite = new Benchmark.Suite; suite .add('function#A', function() { return Math.sqrt(Math.pow(point.x1 - point.x2, 2) + Math.pow(point.y1 - point.y2, 2)); }) .add('function#B', function() { var x = point.x1 - point.x2, y = point.y1 - point.y2; return Math.sqrt(x*x + y*y); }) // 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 });