node package manager



High performance but limited replacement for setTimeout().

It's about 5-20 times faster and requires 20 times less memory for handling timers (not including callback copies);

Compared to setTimeout() there are some drawbacks that make it limited for using:


npm install perf-timers


var PerfTimers = require('..');
var timer = new PerfTimers();
var now =;
timer.setTimeout(function() {
  console.log('Delay', - now);
}, 1000);
Delay: 1088

Improved usage:

var PerfTimers = require('..');
var handler = function(ids) {
var timer = new PerfTimers(handler, 1);
for (var i = 0; i < 10; i ++) {
    timer.setTimeout('x' + i, 10);
[ 'x0', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9' ]

If you want to use more precise timers on short distances, use shorter interval new PerfTimers(1); If you need timers running for hours it would be better to use longer interval (yes, timer accuracy will be minutewise): new PerfTimers(60 * 1000); A rule of thumb for best performance is to keep interval between average timer / 1000 and average timer / 3.