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

process-stopwatch

v1.0.4

Published

A simple timer utility for NodeJs using the process timer

Downloads

3

Readme

process-stopwatch

A simple stopwatch module for nodeJS using the process timer. Allows for resetting of timer and for creating and working with time splits. This is not guaranteed to be a highly accurate timer, merely a utility for simple time-keeping. If you need a highly accurate process timer, you should look elsewhere.

Also, this module is in active development and is mostly being used in my projects, so it may not work 100%. I'm planning to add tests sometime soon.

Installation

Simply

npm install process-stopwatch

Usage

Basic Usage

The timer's basic usage is to start, read, reset and end the timer, as you'd expect to be able to do with any stopwatch. It does not currently offer a pause capability, but one may be implemented in the future.

const { Timer } = require('process-stopwatch')

const timer = new Timer()

// Start the timer
timer.start() // => JS Date reflecting time started

// Get that start date again
timer.startDate // => That start date again

// Read the time
const time = timer.read() // => Time object reflecting time elapsed

// Accessing time values from Time objects
time.raw // => process.hrtime output array
time.millis // => duration in milliseconds
time.nanos // => duration in nanoseconds

// Reset the timer
timer.reset() // => Time object reflecting time when reset
timer.read() // => Time object reflecing time since reset

// Stop the timer
timer.stop()

Advanced Usage

More advanced usage can be done with splits, which create saved points in time on the timer, which can be accessed and worked with. Note that reset() may not work as expected with splits, as it will only affect the current timer time reference. All splits will be calculated based on time from timer start, and will not take into account timer resets. However, reset() can still be used to provide in-progress time tracking, as is shown in an example below.

The decision to ignore resets within the splits was made to avoid making the module opinionated on how to handle it. If you need an implementation that does account for resets in splits, you should be able to use the functionality of this module to implement it using some combination of the split getters with since() and between(), or by using multiple timers.

// Add a split
timer.split('split1') // => Time object reflecting time when split

// Add a split and restart the timer
timer.split('split2', { reset: true }) // => Time object reflecting time when split

// Log the time since the timer reset on split2
timer.read() // => Time object reflecting time elapsed since last reset

// Log it every second
setTimeout(() => console.log(timer.read()), 1000)

// Get splits
timer.splits
/* => [
    [ 'start', Time for timer start,
    [ 'split1', Time split1 was created,
    [ 'split2', TTime split2 was created,
    ...
] */

// Get diffs
timer.diffs
/* => [
    [ 'start', Time between start and start (hopefully 0) ],
    [ 'split1', Time between start and split1 ],
    [ 'split2', Time between split1 and split2 ],
    ...
] */

// Get time since start
timer.since() // => Time since start

// Get time since split1
timer.since('split1') // => Time since split1

// Get time between split1 and split2
timer.between('split1', 'split2') // => Time from split1 to split2

// Get total time over life of timer
timer.between('start', 'end')