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

@universal-packages/time-measurer

v1.4.10

Published

Utility to measure routines times with precision

Downloads

50,942

Readme

Time Measurer

npm version Testing codecov

Time Measurer is a simple wrap for process.hrtime.bigint to measure time with procession and express that time easily through formatted representations, anytime you want to express how much a query or a request took at code level you may want to give this a try.

Install

npm install @universal-packages/time-measurer

Global methods

startMeasurement()

Creates a new TimeMeasurer instance to start a measurement.

import { startMeasurement } from '@universal-packages/time-measurer'

async function getAll() {
  const measurer = startMeasurement()
  const data = await myDB.getAllRecords()
  const measurement = measurer.finish()

  console.log('All records - ', measurement.toString())
}

getAll()
// > All records - 2.23ms

sleep(milliseconds: number)

Time measurer ships with a convenient sleep function that takes a single parameter time in milliseconds, internally it is just a promise with a timeout that resolves it.

import { sleep } from '@universal-packages/time-measurer'

async function awaitable() {
  await sleep(2000)
}

TimeMeasurer

Class TimeMeasurer provides an instantiable interface to start measuring time from any part of your code. The measurement starts at instancing time.

import { TimeMeasurer } from '@universal-packages/time-measurer'

async function getAll() {
  const measurer = new TimeMeasurer()

  measurer.start()

  const data = await myDB.getAllRecords()
  const measurement = measurer.finish()

  console.log('All records - ', measurement.toString())
}

getAll()
// > All records - 2.23ms

Instance methods

start()

Resets the initial time.

stop()

Returns a measurement representing the time passed from when start was called.

Measurement

A Measurement object is the time representation after a measure, it provides the interface to express time as a formatted string or even as a date object.

Instance methods

toString(format: TimeFormat)

Get the time representation as a string, this function takes one param TimeFormat, that can be one of Condensed, Human, Expressive, default: Human.

Example output

2hrs 35min 51.235sec
2:35:51.235
2hrs 35min 51.235sec
2 Hours, 35 Minutes, and 51.235 Seconds

It will take into account parts of the representation that are not contributing to the time, like if the measurement only took seconds, minutes and hours will not be included.

51.235sec
51.235
51.235sec
51.235 Seconds

toDate()

Get the time representation as a date object this can be helpful if you want to use the Date api to format or do whatever with the date.

Typescript

This library is developed in TypeScript and shipped fully typed.

Contributing

The development of this library happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving this library.

License

MIT licensed.