Nodejs console.timeLog() Method

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");
}

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");

chevron_right


Output:

Reference: https://nodejs.org/api/console.html#console_console_timelog_label_data

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.