The console.timeLog() method is an inbuilt function in Nodejs that is used to display the time for each execution. This function is proved to be effective when used in a loop.
Syntax:
console.log([label][, ...data])
Parameters: This function accepts two or more parameters.
Return Value: This method displays the time for the execution.
Below examples illustrate the console.timeLog() method in Node.js:
Example 1:
// Node.js program to demonstrate the // console.timeLog() method // Time started console.time( "executionTime" );
for (let i = 0; i < 10; i++) {
// Printing execution time for each
console.timeLog( "executionTime" );
} |
Output:
Example 2:
// Node.js program to demonstrate the // console.timeLog() method // Time started console.time( "totalExecutionTime" );
// Time started console.time( "executionTime" );
for (let i = 0; i < 10; i++) {
// Printing execution time for each
console.timeLog( "executionTime" );
} // Printing total execution time console.timeLog( "totalExecutionTime" );
|
Output:
Reference: https://nodejs.org/api/console.html#console_console_timelog_label_data