nanotiming
Advanced tools
Comparing version
18
index.js
@@ -0,1 +1,2 @@ | ||
var onIdle = require('on-idle') | ||
var assert = require('assert') | ||
@@ -17,7 +18,7 @@ | ||
return function (cb) { | ||
function end (cb) { | ||
var endName = 'end-' + uuid + '-' + name | ||
perf.mark(endName) | ||
ric(function () { | ||
onIdle(function () { | ||
var measureName = name + ' [' + uuid + ']' | ||
@@ -27,17 +28,12 @@ perf.measure(measureName, startName, endName) | ||
perf.clearMarks(endName) | ||
if (cb) { | ||
var measure = perf.getEntriesByName(measureName)[0] | ||
cb(measure, name) | ||
} | ||
if (cb) cb(name) | ||
}) | ||
} | ||
} | ||
function ric (cb) { | ||
if (this.hasIdleCallback) window.requestIdleCallback(cb) | ||
else setTimeout(cb, 0) | ||
end.uuid = uuid | ||
return end | ||
} | ||
function noop (cb) { | ||
if (cb) ric(cb) | ||
if (cb) onIdle(cb) | ||
} |
@@ -5,3 +5,3 @@ { | ||
"repository": "yoshuawuyts/nanotiming", | ||
"version": "5.2.1", | ||
"version": "6.0.0", | ||
"scripts": { | ||
@@ -13,3 +13,5 @@ "deps": "dependency-check . && dependency-check . --extra --no-dev", | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"on-idle": "^3.0.1" | ||
}, | ||
"devDependencies": { | ||
@@ -16,0 +18,0 @@ "dependency-check": "^2.8.0", |
@@ -40,6 +40,9 @@ # nanotiming [![stability][0]][1] | ||
### `endTiming([cb(timing, name)])` | ||
### `endTiming.uuid` | ||
The unique ID created for the timing. | ||
### `endTiming([cb(name)])` | ||
Close the timing. Measuring the timing is done inside a `requestIdleCallback()` | ||
tick, so it might not be available immediately. If a callback is passed it will | ||
be called with the timing. | ||
be called with the timing's name. | ||
@@ -46,0 +49,0 @@ ## License |
63
5%5070
-0.8%1
Infinity%28
-12.5%+ Added
+ Added
+ Added