| Node.js console.time()
Node.js console.time() Method
When we say about the console close of node.js, console.time() is method is also a console class. And we can used timer to compute the time taken by any piece of code or function. And method console.timeEnd() is used to stop the timer and then the output of elapsed time in milliseconds to stdout. And the timer can be accurate to the sub-millisecond.
And syntax of console.time method is:-'
console.time ( label )
And when we say about the Parameter, this will accepts a single parameter label which can be passed in the method as parameter. And if we not passed the label then a default label is automatically given to the method. And label can be different for different functions or the pieces of code.
Below we have tried to give one example to use of time() method. I have save the below code in .js file and name this file as TimerUsed.js:-
To download code
click here
Now we run above file in Node.js command prompt as per the below command:-
Node TimerUsed.js
And output of above command is given below:-
Now example two and use of Label in console.time() method. And create a below code file and name that file as "TimerUsedLabel.js".
To view the code Download Code
Now we run above file in Node command prompt as per the below command:-
Node TimerUsedLabel.js
And output of above command is given below:-
We will take one more example which have 2 labels and time() method use below is code file which name as MultiTimeLabel.js.
To view the code Download Code
Now we run above file in Node command prompt as per the below command:-
Node MultiTimeLabel.js
And output of above command is given below:-
| | |