Home > OS >  How to do a micro-benchmark in node.js / unit test code
How to do a micro-benchmark in node.js / unit test code

Time:11-21

I'm writing some unit tests using mocha and want to do a micro benchmark around a piece of code

Something like this

const startTime = getTime();
doOperations();
const endTime = getTime();
console.log(startTime - endTime);

is this possible in Javascript / nodejs / mocha?

I'd like to run this in my test environment just to check speed of some critical operations on nodejs server side

CodePudding user response:

For browser

Use performance.measure() API

For Node.js

Use similar performance.measure API

For just console logging , you could use console.time API alongwith console.timeLog and console.timeEnd

  • Related