Gathering detailed insights and metrics for nanotimer
Gathering detailed insights and metrics for nanotimer
Gathering detailed insights and metrics for nanotimer
Gathering detailed insights and metrics for nanotimer
A much higher accuracy timer object that makes use of the node.js hrtime function call.
npm install nanotimer
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
ISC License
156 Stars
101 Commits
21 Forks
8 Watchers
1 Branches
6 Contributors
Updated on Nov 05, 2024
Latest Version
0.3.15
Package Id
nanotimer@0.3.15
Size
251.23 kB
NPM Version
3.10.10
Node Version
6.11.0
Published on
Aug 05, 2017
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A much higher accuracy timer object that makes use of the node.js hrtime function call.
The nanotimer recreates the internal javascript timing functions with higher resolution.
1 2var NanoTimer = require('nanotimer'); 3 4var timerA = new NanoTimer(); 5 6
Each nanotimer object can run other functions that are already defined. This can be done in 2 ways; with either a literal function object, or with a function declaration.
1var NanoTimer = require('nanotimer'); 2var timerObject = new NanoTimer(); 3 4 5var countToOneBillion = function () { 6 var i = 0; 7 while(i < 1000000000){ 8 i++; 9 } 10}; 11 12var microsecs = timerObject.time(countToOneBillion, '', 'u'); 13console.log(microsecs);
or something like this:
1var NanoTimer = require('nanotimer'); 2 3function main(){ 4 var timerObject = new NanoTimer(); 5 6 var microsecs = timerObject.time(countToOneBillion, '', 'u'); 7 console.log(microsecs); 8} 9 10function countToOneBillion(){ 11 var i = 0; 12 while(i < 1000000000){ 13 i++; 14 } 15} 16 17main();
1var NanoTimer = require('nanotimer'); 2 3var count = 10; 4 5 6function main(){ 7 var timer = new NanoTimer(); 8 9 timer.setInterval(countDown, '', '1s'); 10 timer.setTimeout(liftOff, [timer], '10s'); 11 12 13 14} 15 16function countDown(){ 17 console.log('T - ' + count); 18 count--; 19} 20 21function liftOff(timer){ 22 timer.clearInterval(); 23 console.log('And we have liftoff!'); 24} 25 26main();
Instead, it can be done by specifying a callback to setTimeout, since the timer object will exist in that scope. Like so:
1timer.setTimeout(liftOff, '', '10s', function(){ 2 timer.clearInterval(); 3});
1console.log("It's gonna be legen-wait for it..."); 2 3timerA.setTimeout(dary, '', '2s'); 4 5function dary(){ 6 console.log("dary!!"); 7}
1timerA.setInterval(task, '100m', function(err) { 2 if(err) { 3 //error 4 } 5});
1 2var runtimeSeconds = timerA.time(doMath, '', 'u'); 3 4function doMath(){ 5 //do math 6} 7
To time something asynchronous, you only need to do these 3 things:
It's essentially a chain of callbacks, which is probably already familiar to you. Here's an example that times how long it takes to read a file. Suppose you're using node.js's fs.ReadFile, which is asynchronous, then create a wrapper like so:
1var NanoTimer = require('nanotimer'); 2var fs = require('fs'); 3 4var timer = new NanoTimer(); 5 6 7timer.time(loadFile, '', 'u', function(time){ 8 console.log("It took " + time + " microseconds to read that file!"); 9}); 10 11function loadFile(callback){ 12 fs.readFile('testReadFile.js', function(err, data){ 13 if(err) throw err; 14 console.log(data); 15 16 callback(); 17 }); 18}
1timer.clearInterval();
1timer.clearTimeout();
1timer.hasTimeout();
mocha -R spec -t 10000
Version 0.3.1 brings about a potentially massive performance boost over previous versions.
Previous versions used a setImmediate loop running as fast as possible for checking when to execute, inside setTimeout and setInterval. In 0.3.1, this has changed when using an intervalTime (setInterval), or delayTime (setTimeout) that is longer than 25ms. Execution will be deferred to the standard javascript setTimeout, aimed for 25ms before scheduled execution, where the setImmediate loop will resume.
The assumed error of javascript's setTimeout is 25ms.
Below is a test case with setInterval set to 1 second.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 6/30 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More