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-pretty-hrtime

v1.0.0

Published

Converts a time in nanoseconds to a pretty string in the most convenient units.

Downloads

6

Readme

atlas-pretty-hrtime

Converts a time in nanoseconds to a pretty string in the most convenient units.

Travis


install

npm install --save atlas-pretty-hrtime

why

Printing times is annoying, so this is me thinking about it once and hopefully never again. If you are doing performance testing, you will encounter time diffs between different points in your code. With this module, you don't need to worry about how to print those times in various units with varying precision -- it's done automatically for you.

examples

The exported function takes a time in nanoseconds, an optional precision integer and returns a string. The default precision is 3 decimal places, and the maximum unit is hours.

const pretty = require("atlas-pretty-time");
// all times in nanoseconds
const times = [  
                 // output units:
  0,             // ns
  123,           // ns
  1234,          // us
  12345,         // us
  123456,        // us
  1234567,       // ms
  12345678,      // ms
  123456789,     // ms
  1234567890,    // sec
  12345678901,   // sec
  123456789012,  // min
  1234567890123, // min
  12345678901234 // hr
]
times.forEach(time => {
  // round to 1 decimal place
  const prettyTime = pretty(time, 1);
  console.log(prettyTime)
});
// 0.0ns
// 123.0ns
// 1.2us
// 12.3us
// 123.5us
// 1.2ms
// 12.3ms
// 123.5ms
// 1.2sec
// 12.3sec
// 2.1min
// 20.6min
// 3.4hr

caveats

units

Only accepts times in nanoseconds, because supporting multiple input units is outside the scope of this package. This package is primarily for printing time diffs, which should not be in milliseconds or seconds if you're using high resolution time. See atlas-hrtime.

fractional minutes and hours

For simplicity, this module does not decompose fractional minutes into "minutes and seconds" (and similarly with hours). This doesn't bother me much, so I'm unlikely to implement something like:

console.log(pretty(123456789012, 1))
// 2min 3sec

specifying return units

At the moment, this is not possible, but I may implement it in the future if I need finer-grained control on the output units:

console.log(pretty(123456789012, 1, "sec"))
// 123.5sec