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

time-logger

v0.3.1

Published

Utility library for tracking and tallying function calls in browsers, Node, or Arangodb's Foxx

Downloads

43

Readme

time-logger

npm version travis build lgtm code quality

Utility library for tracking min / max / average evaluation time and tallying number of calls to code a code block in javascript. A more robust version of console.time and console.timeEnd.

Use

// in node
const TimeLogger = require('time-logger')

TimeLogger.begin('timing-label')
// ... code that needs to be profiled
TimeLogger.end('timing-label')
TimeLogger.dump('timing-label')
TimeLogger.clear('timing-label')

The above will print out the average, min, max, and call count of the code wrapped by timing-label:

timing-label         calls: 2        avg: 1532.5ms                  min: 1416.23ms                    max: 1649.1ms

Calling dump() and clear() with no arguments will print and clear all accumulated timing metrics

API

getTime()

Returns the current time with highest precision method available (described below).

begin(key)

Marks the beginning of the code block to track. A warning is printed and no changes are made if the provided key is already being tracked.

key : String

The identifier to use for the given code block.

end(key)

Marks the end of the block of code to track timing and tallies for. A warning is printed if a corresponding begin call has not been made.

key : String

The identifier of the code block to end.

clear(key = null)

Clears both pending and cached information for the provided key so timing can be started fresh.

key : String

The identifier to clear tracked information for. If null then all tracked and pending data is cleared.

dump(key = null, clear = false)

Prints out timing information associated with provided key.

key : String

The identifier to print the information for. If null then all information and pending data is cleared.

clear : Boolean

Whether or not to call "clear" on the key after printing.

getTimingData(key, createCopy = true) : Object

Returns the data associated with the provided key in the form of an object:

{

    // the average time spent evaluating the code block
    avg: number,

    // the minimum and maximum amount of time
    min: number,
    max: number,

    // the number of times a code block was executed
    tally: number,

}

key : String

The identifier to get the associated data for.

createCopy : Boolean

Whether or not to create a new object with the timing and tally data. If false then it is expected that this object is not modified because it is used internally.

getAllTimingData(createCopy = true) : Object

Returns all available timing data in object form.

createCopy

See getTimingData.

getPending() : Array

Returns an array of all identifiers that have not had "end" called.

Precision

The most precise timing measurements available are used depending on the platform. In browsers, performance.now() is used to get timing data, in Node process.hrtime() is used, and in Arangodb's Foxx require('internal').time is used.

When a precision timing function is unavailable, Date.now() is used, which gives coarse, millisecond precision.