0

I have nodejs application with a lot of functions.

How can I log how much time takes to execute each function?

for example, my app should execute a lot of functions:

execfn1(); -> should output in some log, takes: 1ms..
execfn2(); -> should output in some log, takes: 2ms..
execfn3(); -> should output in some log, takes: 3ms..
execfn4(); -> should output in some log, takes: 5ms..
execfnN(); -> should output in some log, takes: 7ms..

I can't wrap every function in begin and end like: var endtimer = starttimer(execfnN);

jack bauer
  • 21
  • 5

1 Answers1

0

Use process.hrtime which is fast and returns the time in nanoseconds.

It's the usual solution to measure short durations in node.

Most often you'll still need to measure repeated operations to have meaningful numbers. You do that either by looping or by using an accumulator (exemple of accumulator for node micro benchmarking).

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758