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

perfmate

v1.0.0

Published

This module represents a class for measuring and logging code execution time, both in browser and in node.js, based on [performance.now()](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now) and [process.hrtime.bigint()](https://nodejs.org/a

Downloads

106

Readme

perfmate npm GitHub license

This module represents a class for measuring and logging code execution time, both in browser and in node.js, based on performance.now() and process.hrtime.bigint()

Every instance of the class created contains

  • a start time (now is set on creation)
  • an end time

All methods of the class manipulate the start or/and end time or print their difference.

Installation

$ yarn add perfmate
import PerfMate from "perfmate";
// OR
const PerfMate = require("perfmate").default;

Usage Examples

Basic

const perf = new PerfMate()
// your code ~ 100ms
perf.log("named label1"); // named label1: 100.011

Custom message

const perf = new PerfMate()
// your code ~ 100ms
console.log(`named label2, diff is ${perf.end().diff(0)}ms`) /// named label2, diff is 100ms
// end() used here can be omitted just to perf.diff() if you don't need to stop

Warning and Error

const perf = new PerfMate()
// your code ~ 100ms
perf.warn("named label3"); // named label3: 100.012
perf.error("named label4"); // named label4: 100.014
// both are aliases for console.warn and console.error

Reset and reuse

const perf = new PerfMate()
// your code ~ 100ms
perf.log("named label5"); // named label5: 100.008
perf.clear();
// your code ~ 200ms
perf.log("named label6"); // named label6: 200.014

Stop and remember

const perf = new PerfMate()
// your code ~ 100ms
perf.log("named label7"); // named label7: 100.006
// your code ~ 100ms
perf.log("named label8"); // named label8: 200.013
perf.end();
// your code ~ 200ms
perf.log("named label9"); // named label9: 200.013

API

diff(round)

  • round: number, default value is 3

Returns the difference between the time when the instance of the class was created (or when the last clear was called) and now. Doesn't set the end time.

end()

Sets the end time as now.

clear()

Sets the start time as now.

log(message, round)

  • message: string
  • round: number, default value is 3

console.log's the difference between start time and end time, if end time is not set, now is used instead.

warn(message, round)

  • message: string
  • round: number, default value is 3

console.warn's the difference between start time and end time, if end time is not set, now is used instead.

error(message, round)

  • message: string
  • round: number, default value is 3

console.error's the difference between start time and end time, if end time is not set, now is used instead.