nanotiming
Advanced tools
Comparing version 5.0.0 to 5.1.0
22
index.js
var assert = require('assert') | ||
var hasPerf = typeof window !== 'undefined' && | ||
window.performance && window.performance.mark | ||
var perf = window.performance | ||
var hasPerf = typeof window !== 'undefined' && perf && perf.mark | ||
@@ -13,15 +13,19 @@ module.exports = nanotiming | ||
var uuid = (window.performance.now() * 100).toFixed() | ||
var uuid = (perf.now() * 100).toFixed() | ||
var startName = 'start-' + uuid + '-' + name | ||
window.performance.mark(startName) | ||
perf.mark(startName) | ||
return function () { | ||
return function (cb) { | ||
var endName = 'end-' + uuid + '-' + name | ||
window.performance.mark(endName) | ||
perf.mark(endName) | ||
ric(function () { | ||
var measureName = name + ' [' + uuid + ']' | ||
window.performance.measure(measureName, startName, endName) | ||
window.performance.clearMarks(startName) | ||
window.performance.clearMarks(endName) | ||
perf.measure(measureName, startName, endName) | ||
perf.clearMarks(startName) | ||
perf.clearMarks(endName) | ||
if (cb) { | ||
var measure = perf.getEntriesByName(measureName)[0] | ||
cb(measure) | ||
} | ||
}) | ||
@@ -28,0 +32,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"repository": "yoshuawuyts/nanotiming", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"scripts": { | ||
@@ -8,0 +8,0 @@ "deps": "dependency-check . && dependency-check . --extra --no-dev", |
@@ -40,5 +40,6 @@ # nanotiming [![stability][0]][1] | ||
### `endTiming()` | ||
### `endTiming([cb(timing)])` | ||
Close the timing. Measuring the timing is done inside a `requestIdleCallback()` | ||
tick, so it might not be available immediately. | ||
tick, so it might not be available immediately. If a callback is passed it will | ||
be called with the timing. | ||
@@ -45,0 +46,0 @@ ## License |
5078
30
60