exec-time
IMPORTANT: this library is not maintained anymore, please don't submit anymore pull requests except for bugfixes
See how much time every step of a node script takes, with nanosecond precision.
var execTime = profiler = 'demo1'; profiler;// DB access taking 350ms hereprofiler;// Data processing taking 850msprofiler;// Rendering taking 120msprofiler; /* Outputdemo1 - Beginning profilingdemo1 - Accessed DB - 350ms (total: 350ms)demo1 - Processed data - 850ms (total: 1.2s)demo1 - Rendered page - 120ms (total: 1.3s)*/
You can disable logging to the console by passing in false
after the timer name and access the steps later.
var execTime = profiler = 'demo2' false; profiler;// DB access taking 350ms hereprofiler;// Data processing taking 850msprofiler;// Rendering taking 120msprofiler; console; /* Output[ [ 'Accessed DB', 350 ], [ 'Processed data', 850 ], [ 'Rendered page', 120 ] ]*/
The third paramter to execTime()
is precision
, which you can set to ms
or ns
, to show times in milliseconds or nanoseconds, respectively.
You can reset the timer by using the resetTimers
function:
var execTime = profiler = 'demo2'; profiler;// DB access taking 350ms hereprofiler;// Data processing taking 850msprofiler;profiler;// Rendering taking 120msprofiler; /* Outputdemo2 - Beginning profilingdemo2 - Accessed DB - 350ms (total: 350ms)demo2 - Processed data - 850ms (total: 1.2s)demo2 - Rendered page - 120ms (total: 120ms) // Timers were reset*/
You can directly access the current timer values (in the timer's
precision) with the
elapsedSinceBeginning
and elapsedSinceLastStep
methods:
var execTime = profiler = 'demo3'; profiler;// DB access taking 350ms hereprofiler;// Data processing taking 850msprofiler;console;console; /* Outputdemo3 - Beginning profilingdemo3 - Accessed DB - 350ms (total: 350ms)demo3 - Processed data - 850ms (total: 1.2s)Number of ms since the last step: 850Number of ms since the beginning: 1200*/