Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nanotiming

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nanotiming

Small timing library

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32K
increased by20.78%
Maintainers
1
Weekly downloads
 
Created
Source

nanotiming stability

npm version build status downloads js-standard-style

Small timing library. Useful to integrate into libraries that have multiple methods. Only works in the browser, does nothing in Node.

Usage

var nanotiming = require('nanotiming')
var timing = nanotiming('my-timing')

// make sure the buffer doesn't overflow, set this once per application
if (typeof window !== 'undefined' &&
  window.performance &&
  window.performance.getEntriesByName) {
  window.performance.onresourcetimingbufferfull = function () {
    window.performance.clearResourceTimings()
  }
}

timing.start('my-loop')
var i = 1000
while (--i) console.log(i)
timing.end('my-loop')

var timings = window.performance.getEntriesByName('my-timing:my-loop')
console.log(timings[timings.length - 1]) // log the last entry

API

timing = nanotiming([instanceName])

Create a new Nanotiming instance. Takes a name for the timing instance.

timing.start([methodName])

Start a timing. Takes a method name. The method name is concatenated to the instance name as <instanceName>:<methodName>. If no method name is passed, it'll fall back to only using the instance name. It's recommended that per instance to either always use method names, or never.

timing.end([methodName])

End a timing. The name here must be the same as timing.start(). If using a static name, the timing.end() call must resolve on the same tick as timing.start() to prevent race conditions. If you want to do use this in async conditions make sure the name is unique, for example by appending a unique id to both start and end.

License

MIT

Keywords

FAQs

Package last updated on 14 Apr 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc