1.0.1 • Published 6 years ago
tmc-debug-function-timer v1.0.1
tmc-debug-function-timer
Rudimentary function timer/profiler - helps to determine the duration of different functions run. Uses milliseconds or nanoseconds. Can call functions singular or recursively.
Install
npm install tmc-debug-function-timer
Usage
const fnTimer = require('tmc-debug-function-timer');
const quickFunction = ()=>{};
const slowFunction = ()=>{fnTimer.blockMs(Math.floor(1500 * Math.random() ));}
result =fnTimer.single(quickFunction);
// result:{"start":555616.075955114,"finish":555616.076044967,"elapse":0.00008985307067632675,"timeUnit":"ns"}
fnTimer.setTimerMilliseconds();
result =fnTimer.single(slowFunction);
//result:{"start":1534651924019,"finish":1534651925019,"elapse":1000,"timeUnit":"ms"}
fnTimer.setTimerMilliseconds();
result =fnTimer.recursive(slowFunction,3);
//result:{"start":1534652336646,"finish":1534652338902,"elapse":2256,"timeUnit":"ms","most":836,"least":610,"total":2256,"overhead":0,"average":752}
fnTimer.setTimerNanoseconds();
result =fnTimer.recursive(slowFunction,3);
//result:{"start":557216.621176887,"finish":557216.621334321,"elapse":0.00015743402764201164,"timeUnit":"ns","most":0.000009603914804756641,"least":0.000001710955984890461,"total":0.000013525830581784248,"overhead":0.0001439081970602274,"average":0.0000045086101939280825}
recursive(function, int number_of_calls)
Possible option values
- function the function to be be timed
number_of_calls number of times to call the function.
returns:
{
"start":[time started],
"finish":[time finished],
"elapse":[difference between start and finish],
"timeUnit":["ns"|"ms"],
"most":[longest running function call],
"least":[shortest running function call],
"total":[total time for all functions calls],
"overhead":[difference between elapsed and total time spend on function calls],
"average":[total time / number of calls]
}
*uses recursion - a machine's stack size seems to be hardware dependant -- not thoroughly tested.
single(function)
Possible option values
function the function to be be timed
returns:
{
"start":[time started],
"finish":[time finished],
"elapse":[difference between start and finish],
"timeUnit":["ns"|"ms"]
}
setTimerMilliseconds() and setTimerNanoseconds()
milliseconds uses integers and very crude implementation. Best used for simple calls and user output
nanoseconds uses floats and hrtime()
License
BSD