DEV Community

Omar Dulaimi
Omar Dulaimi

Posted on • Updated on

How to measure CPU time in Nodejs?

The ๐—ฝ๐—ฟ๐—ผ๐—ฐ๐—ฒ๐˜€๐˜€.๐—ฐ๐—ฝ๐˜‚๐—จ๐˜€๐—ฎ๐—ด๐—ฒ method returns the user and system CPU time usage of the current process, in microseconds.

These values measure time spent in user and system code respectively, and may end up being greater than actual elapsed time if multiple CPU cores are performing work for this process.

The result of a previous call to ๐—ฝ๐—ฟ๐—ผ๐—ฐ๐—ฒ๐˜€๐˜€.๐—ฐ๐—ฝ๐˜‚๐—จ๐˜€๐—ฎ๐—ด๐—ฒ can be passed as the argument to the function, to get a diff reading.

Of course, this method can be used with the ๐—ป๐—ผ๐—ฑ๐—ฒ:๐—ผ๐˜€ module to calculate the CPU usage percentage. I'll post about that later.

Did you learn something new today?

Like and share this post, and follow me for more!

cpu usage

Top comments (0)