A quick and easy way to measure the performance of your method in JavaScript and TypeScript.
Photo by Dawid Małecki on Unsplash
Measuring the performance of a certain method in JavaScript or any other language is actually pretty simple and generally can be split up into 4 parts.
So what you would do in your JavaScript is shown in the next snippet:
const myMethod = () => {
const startTimeInMs = new Date().getTime();
// Do some heavy computation
// ..........
// ////////////////////////////////////////
const endTimeInMs = new Date().getTime();
const durationInMs = endTimeInMs - startTimeInMs;
console.log(`myMethod took ${durationInMs} ms`);
};
#programming #typescript #javascript