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

atlas-hrtime

v1.0.1

Published

Returns arbitrary time diffs in nanoseconds, falling back to performance.now or Date.now if process.hrtime is not available.

Downloads

5

Readme

atlas-hrtime

Returns arbitrary time diffs in nanoseconds, falling back to performance.now or Date.now if process.hrtime is not available.

Travis


install

npm install --save atlas-hrtime

why

process.hrtime, performance.now and Date.now are not consistent. This module exports a clock which uses whichever one is available (in the precedence defined here), where all units are normalized to nanoseconds. This module is meant for time diffs, not asking for the current datetime. If you need the current datetime, use javascript's built-in Date function or a wrapper library like moment.

examples

recording a time

To record the time in nano-seconds, just call the clock:

const clock = require("atlas-hrtime")();
console.log(`current time measured from an arbitrary time in the past is ${clock()}ns`)

calculating a time diff

Let's say you need to test how long your arraySort algorithm takes. All you need to do is call the clock before running your sort, then call it after running your sort with the previous time as the argument:

...
const initialTime = clock()
arraySort(myLongArray)
const deltaTime = clock(initialTime)
console.log(`arraySort took ${deltaTime}ns to sort myLongArray`)

calculating multiple time diffs

Alternatively, you can record down times at certain points and then manually log the diffs:

...
const t0 = clock()
quickSort(getLongArray())
const t1 = clock()
heapSort(getLongArray())
const t2 = clock()
insertionSort(getLongArray())
const t3 = clock();
console.log(`quickSort took ${t1-t0}ns`)
console.log(`heapSort took ${t2-t1}ns`)
console.log(`insertionSort took ${t3-t2}ns`)

caveats

calling the module

Make sure you call the module before using it (e.g. require("atlas-hrtime")()). The return value of the exported function is the clock. This was done to keep the module easily testable.

units

All units are in nanoseconds, plain and simple -- this keeps the module minimal. You can convert to other units manually.