Home > Enterprise >  Is there a way to list all nodejs function execution time?
Is there a way to list all nodejs function execution time?

Time:11-01

Is there a way to measure execution time of nodejs functions recursively? console.time and performance.mark can only get the total time, but what I want is to list all inner function's time, like this way:

function A() {
  B();
  C();
}
function B() {
  ...
}
function C() {
  ...
}

// some tool like timeit
timeit('A')
A();
timeit('A')

I wanna get the result like below:

A: 1000ms
- B: 400ms
- C: 600ms

and if there's any extensions in vscode can do it will be better, like in chrome we can see React Profiler

An Example of React Profiler to list all components execution time

CodePudding user response:

There is a Node.js Profiler that can do that. You can find more information here https://nodejs.org/en/docs/guides/simple-profiling/

Also, it is possible to load the profiler output to Chrome to see nice visualization of the profiling data.

Apart from that, you could create a flame chart to analyze your application execution, for example here is a good guide https://betterprogramming.pub/create-a-flame-graph-for-your-node-app-profiling-nodejs-app-e0a91e5ed585

  • Related