Utility library for tracking min / max / average evaluation time and tallying number of calls to code a code block in javascript. A more robust version of console.time
and console.timeEnd
.
// in node
const TimeLogger = require('time-logger')
TimeLogger.begin('timing-label')
// ... code that needs to be profiled
TimeLogger.end('timing-label')
TimeLogger.dump('timing-label')
TimeLogger.clear('timing-label')
The above will print out the average, min, max, and call count of the code wrapped by timing-label
:
timing-label calls: 2 avg: 1532.5ms min: 1416.23ms max: 1649.1ms
Calling dump()
and clear()
with no arguments will print and clear all accumulated timing metrics
Returns the current time with highest precision method available (described below).
Marks the beginning of the code block to track. A warning is printed and no changes are made if the provided key is already being tracked.
The identifier to use for the given code block.
Marks the end of the block of code to track timing and tallies for. A warning is printed if a corresponding begin
call has not been made.
The identifier of the code block to end.
Clears both pending and cached information for the provided key so timing can be started fresh.
The identifier to clear tracked information for. If null then all tracked and pending data is cleared.
Prints out timing information associated with provided key.
The identifier to print the information for. If null then all information and pending data is cleared.
Whether or not to call "clear" on the key after printing.
Returns the data associated with the provided key in the form of an object:
{
// the average time spent evaluating the code block
avg: number,
// the minimum and maximum amount of time
min: number,
max: number,
// the number of times a code block was executed
tally: number,
}
The identifier to get the associated data for.
Whether or not to create a new object with the timing and tally data. If false
then it is expected that this object is not modified because it is used internally.
Returns all available timing data in object form.
See getTimingData
.
Returns an array of all identifiers that have not had "end" called.
The most precise timing measurements available are used depending on the platform. In browsers, performance.now()
is used to get timing data, in Node process.hrtime()
is used, and in Arangodb's Foxx require('internal').time
is used.
When a precision timing function is unavailable, Date.now()
is used, which gives coarse, millisecond precision.