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

node-perf-timer

v0.1.1

Published

Downloads

357

Readme

node-perf-timer Build Status Coverage Status

Measuring elapsed time in Node, made simple.

Motivation

Node's native timing function – process.hrtime() – is extremely precise, but low-level and messy to use for profiling without any abstraction on top of it.

node-perf-timer aims to provide a simple API to provide a more intuitive developer experience when measuring elapsed time in Node applications.

Requirements

  • Node v4.x or higher

Installation

npm i --save-dev node-perf-timer

or

yarn add node-perf-timer --dev

Usage

const perfTimer = require('node-perf-timer')

// start a timer
perfTimer.start();

functionToBeMeasured();

// returns diff in nanoseconds & logs (by default):
// Message: functionToBeMeasured()
// Duration: 0 s, 3.589862 ms
const nsDiff = perfTimer.stopAndDiff('functionToBeMeasured()');

Configuration

By default, the configuration object takes the following shape:

const opts = {
  shouldPrint: true, // should diffs be logged to the console?
  precision: undefined, // e.g. `4`; how many decimal places to use for millisecond formatting
  defaultMessage: undefined, // e.g. `"hello bottleneck!"`; default message for each diff being logged
};

API

  • config(configObj) - Adjust default opts for all future perfTimer calls.
  • start() - Starts a new timer and returns the absolute start time in nanoseconds.
  • stop() - Stops the current timer and returns the absolute end time in nanoseconds.
  • diff(nsStartTime, nsEndTime) - Accepts a start & end time in nanoseconds and returns the difference.
  • stopAndDiff(message?) - Combines stop() & diff(). If opts.shouldPrint is set, the diff is logged to the console with message, opts.defaultMessage or simply the duration.
  • stopAndRestart() - Stops timer, starts a new one and returns the nanosecond diff of the stopped timer.

Full API Documentation

Examples

Examples for a number of common use cases can be found here (WIP).

License

MIT