Socket
Socket
Sign inDemoInstall

perf-timers

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

perf-timers

High performance limited replacement for setTimeout().


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 22 Oct 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc