Node.js console.time() Method Last Updated : 13 Oct, 2021 Comments Improve Suggest changes Like Article Like Report The console.time() method is the console class of Node.js. It is used to starts a timer that is used to compute the time taken by a piece of code or function. The method console.timeEnd() is used to stop the timer and output the elapsed time in milliseconds to stdout. The timer can be accurate to the sub-millisecond. Syntax console.time( label ) Parameter: This method accepts a single parameter label that can be passed in the method as a parameter and if the label is not passed default label is automatically given to the method. The label can different for different functions or pieces of code. Below examples illustrate the working of console.time() method in Node.js: Example 1: javascript // Node.js program to demonstrate the // console.time() method // Sample function function addCount() { // Variable declaration var sum = 0; for (var i = 1; i < 100000; i++) { // Adding i to the sum variable sum += i; } // Return sum value return sum; } // Starts the timer console.time(); // Function call addCount(); // Ends the timer and print the time // taken by the piece of code console.timeEnd(); Output: default: 8.760ms Example 2: javascript // Node.js program to demonstrate the // console.time() method // Sample function function addCount() { // Variable declaration var sum = 0; for (var i = 1; i < 100000; i++) { // Adding i to the sum variable sum += i; } return sum; // returning sum } var timetaken = "Time taken by addCount function"; // Starts the timer. The label value is timetaken console.time(timetaken); addCount(); // function call // Ends the timer and print the time // taken by the piece of code console.timeEnd(timetaken); Output: Time taken by addCount function: 7.380ms Example 3: This example using the different label for different functions simultaneously. javascript // Node.js program to demonstrate the // console.time() method // Sample function function addCount() { var sum = 0; // Variable declaration for (var i = 1; i < 100000; i++) { sum += i; // Adding i to the sum variable } return sum; // returning sum } function countTime() { var timetaken = "Time taken by addCount function"; // Starts the timer, the label value is timetaken console.time(timetaken); console.log(addCount()); // function call // Ends the timer and print the time // taken by the piece of code console.timeEnd(timetaken); } var label2 = "Time taken by countTime function"; // Starts the timer, the label value is label2 console.time(label2); countTime(); // function call // Ends the timer and print the time // taken by the piece of code console.timeEnd(label2); Output: 4999950000 Time taken by addCount function: 24.884ms Time taken by countTime function: 25.928ms Reference: https://nodejs.org/docs/latest-v11.x/api/console.html#console_console_time_label Comment More infoAdvertise with us A akshajjuneja9 Follow Improve Article Tags : Web Technologies Node.js Node.js-console-module Similar Reads Node.js console.assert() Method The console.assert() method is an inbuilt application programming interface of the console module which is used to assert value passed to it as a parameter, i.e. it checks whether the value is true or not, and prints an error message, if provided and failed to assert the value. Syntax: console.asse 2 min read Node.js console.clear() Method The console.clear() method is used to clear the stdout, when stdout is a TTY (Teletype) i.e. terminal it will attempt to clear the TTY. When stdout is not a TTY, this method does nothing. The console.clear() will work differently across different operating systems and terminal types. For Linux opera 1 min read Node.js console.count() Method The console.count() method is an inbuilt application programming interface of the console module which is used to count label passed to it as a parameter, by maintaining an internal counter for that specific label. Syntax: console.count(label) Parameters: This method has one parameter as mentioned a 2 min read Node.js console.countReset() Method The console.countReset() method is an inbuilt application programming interface of the console module which is used to reset the count for the specific label passed to it as a parameter. Syntax: console.countReset( label ); Parameters: This method has one parameter as mentioned above and described b 2 min read Node.js console.debug() Method The console.debug() method is an inbuilt application programming interface of the console module which is used to print messages to stdout in a newline. Similar to the console.log() method. Syntax: console.debug(data, args); Parameters: This method has two parameters as mentioned above and described 2 min read Node.js console.dir() Method The console.dir() method is used to get the list of object properties of a specified object. These object properties also have child objects, from which you can inspect for further information. Syntax: console.dir( object ) Parameters: This method accepts single parameter which holds the object elem 1 min read Node.js console.error() Function The console.error() function from the console class of Node.js is used to display an error message on the console. It prints to stderr with a newline. Syntax: console.error([data][, ...args]) Parameter: This function can contain multiple parameters. The first parameter is used for the primary messa 1 min read Node.js console.info() Method The console.info() method is an inbuilt application programming interface of the console module which is used to print messages to stdout in a newline. It is similar to the console.log() method. Syntax: console.info(data, args); Parameters: This method has two parameters as mentioned above and descr 2 min read Node.js 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 1 min read Node.js console.time() Method The console.time() method is the console class of Node.js. It is used to starts a timer that is used to compute the time taken by a piece of code or function. The method console.timeEnd() is used to stop the timer and output the elapsed time in milliseconds to stdout. The timer can be accurate to th 3 min read Like