High performance replacement for setTimeout().
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
bench
examples
tests
.gitignore
README.md
package.json
perf-timers.js

README.md

node-perf-timers

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:

Installation

npm install perf-timers

Usage

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

Improved usage:

var PerfTimers = require('..');
var handler = function(ids) {
    console.log(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.