Recipe 16.4
Using Console Timers
To start a timer, call console.time
with a name for your timer. Later, when the task you are timing has completed, call console.timeEnd
with the same timer name. It will stop the timer and print the elapsed time to the console along with its name.
Code
JavaScript
// Start the `loadTransactions` timer
console.time('loadTransactions');
// Load some data
const data = await fetch('/api/users/123/transactions');
// Stop the `loadTransactions` timer
// Prints: "loadTransactions: <elapsed time> ms"
console.timeEnd('loadTransactions');