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')
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])
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