perf

Simple performance analysis tool

npm install perf
1 downloads in the last week
3 downloads in the last month

perf

perf is a tiny module that has some handy functions for comparing performance between different functions.

installation

npm install perf

compare performance of functions

More than one way to do things? Compare performance with perf:

var perf = require('perf');
var functions = {
  'isFunction using toString': function(obj) {
     return toString.call(obj) === '[object Function]';
  },
  'isFunction using typeof': function(obj) {
    return typeof obj === 'function';
  }
}

// runs each function 1,000,000 times and measures the time it takes
console.log(perf(1000000, functions, console.log));
// > { 'isFunction using toString': [ 0, 221068055 ],
//      'isFunction using typeof':  [ 0, 16674850 ] }

Each value in the returned object is an array [seconds, nanoseconds], returned from process.hrtime

check performance of a single function

var perf = require('perf')
  , pass = perf.pass

function times5(num) {
  return num * 5;
}

// this call to pass returns a function that calls times5, passing 10 as a
// parameter
perf.perf(pass(10, times5)); // runs times5 1000 times by default
// > [ 0, 221110 ]

// or you can tell perf how many time to run your function
perf.perf(1000000, pass(10, times5));
// > [ 0, 2683498 ]
npm loves you