nanotiming
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')
timing.start('my-loop')
var i = 1000
while (--i) console.log(i)
timing.end('my-loop')
window.requestIdleCallback(function () {
var name = 'my-timing/my-loop'
var timings = window.performance.getEntriesByName(name)
console.log(timings[timings.length - 1])
performance.clearMeasures(name)
})
API
timing = nanotiming([instanceName])
Create a new Nanotiming instance. Takes a name for the timing instance.
uuid = 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.
Returns a uuid
that should be passed to timing.end()
so async timings work.
timing.end(uuid, [methodName])
End a timing. The name here must be the same as timing.start()
. 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. The performance.measure()
step
is performed in a requestIdleCallback()
tick, so make sure to process
measures asynchronously, and preferably in later idle callbacks.
Takes the uuid that is povided by timing.start()
so async timings work.
License
MIT