Measuring time using console.time
Instead of creating a date object and substracting the current time, use console.time
to start a timer.
Give it a label, add checkpoints using console.timeLog
, and stop the timer using console.timeEnd
// Yucky, but ok
const start = new Date();
await createUser();
console.log(new Date() - start, "createUser");
await sendEmail();
console.log(new Date() - start, "sendEmail");
// ⭐️
console.time("register")
await createUser();
console.timeLog("register", "createUser");
await sendEmail();
console.timeLog("register", "sendEmail");
Way easier to write.
Tags: