1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.