npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

keeptime

v1.5.0

Published

A simple timer class to measure passing of the time.

Downloads

27

Readme

In A Nutshell

KeepTime is a simple class to make time measurements in node.js.

In a simple case, time can be measured just by:

var kt = new KeepTime(true); // timer is autostarted
... // your own code here
console.log('code took ' + kt.get() + ' seconds to run.');

Somewhat more complex measurement:

var kt = new KeepTime(); // timer is not started
for (var i=0; i<42; i++) {
    ... // do something non-interesting here
    kt.start();
    ...
    // do something time critical and interesting here
    // and measure the time cumulatively
    ...
    kt.stop();
    ... // do something non-interesting here
}
console.log('code took ' + kt.get() + ' seconds to run.');

Methods

KeepTime(autoStart)

The constructor method that is used to create a timer object. The timer can optionally be created in automatically started state. If called without argument or with argument evaluating to false, the timer is created in stopped state.

KeepTime.prototype.get()

Look up the current time from a timer and return the time the timer has been running in seconds.

KeepTime.prototype.set(seconds)

Set the timer to given number of seconds. Only finite, non-negative numbers are allowed.

Avoid using ridiculously high values. Above 2^40 seconds, the timer granularity starts to degrade, but since it's already around 6e32 years, it should not be a problem. Below that, it should be ok.

KeepTime.prototype.getReadable(decimals)

Look up the current time from a timer and return the time the timer has been running in a readable string with given number of decimals after seconds. Maximum number of decimals is 9 and the default is 0.

If the time is less than one hour (i.e. 3600 seconds), it's is returned in form 'mm:ss' (followed by possible decimals like other formats). If the time is less than one day, it's returned in format 'hh:mm:ss'. If it's more than a day, it's returned in format 'd+hh:mm:ss'. For time values larger than one year, approximate number of years is added to the string. For ridiculously big values, only approximate number of years is returned and smaller units are omitted altogether, which naturally causes also decimals to be ignored.

In case the least significant parts of the timer value is beyond the precision of number type, the return value is padded with zeros rather than arbitrary digits.

KeepTime.prototype.getArray()

Look up the current time from a timer and return the time the timer has been running as array of two integers. The first number is seconds (rv[0] >= 0) and the second number is fraction of second in nanoseconds (0 <= rv[1] < 1000000000).

KeepTime.prototype.stop()

Stop the timer. While the timer is in stopped state, the calls to get and getArray methods return the same value unless reset is called in between.

KeepTime.prototype.start()

Start (or resume) the timer.

KeepTime.prototype.reset()

Reset the time of the timer to zero. The call does not affect on the run state of the timer (i.e. running timer remains running and stopped timer remains stopped).

KeepTime.prototype.isRunning()

Return true if the timer is running, false if it's stopped.

KeepTime.readable(seconds, decimals)

A static version for converting a number of seconds to a readable string.

Author

Timo J. Rinne [email protected]

License

GPL-2.0