Search This Blog

2023/04/13

Console.time & console.timeend & console.timelog

The console object has time and timeend methods that help with analyzing performance of pieces of your code. You first call  console.time by providing a string argument, then the code that you want to test, then call console.timend with the same string argument. You’ll then see the time it took to run the code  Here’s an example:

Code Snippet 1:

console.time("Sangram");

for (var i = 0; i < 10000; i++) {

    console.timeLog("Sangram");

}

console.timeEnd("Sangram");

The console.timeLog() method logs the current value of a timer that was previously started by calling console.time().

No comments:

Post a Comment