How to measure javascript code with performance.now()

Sometimes, we want to know how is the performance or time spent in some function or process can be solved using performance.now().
performance.now() help us get time in milliseconds, and we can measure the time between some function completing his process.
Using performance.now
We can take the current performance.now() and compare with the same when our function finishes the process, as my example.
function getUsers() {
console.log("Start...")
let from = performance.now();
setTimeout(() => {
console.log("Getting users..")
let to = performance.now()
let total = from - to;
console.log(`Total miliseconds ${total}`);
},3000)
}
// Total miliseconds -3003If you want to learn more about it, please go free to read more:
Modern frontend development — Angular, React, TypeScript, accessibility, and performance.
Related Articles
Share this article
If you found this guide helpful, consider sharing it with your team or fellow developers.
Real Software. Real Lessons.
I share the lessons I learned the hard way, so you can either avoid them or be ready when they happen.
Join 13,800+ developers and readers.
No spam ever. Unsubscribe at any time.