Sometimes you need to measure time execution of a script or part of it, simple answer could be call the Date() function many times and compute elapsed time.
Recently I found out a better method that works for javascript and Node.js too, the console.time.
This function comes from Web API and have a great support:
Using it is very simple:
//start timer with name "My Timer Name"
console.time("My Timer Name");
alert("Click to continue");
//log time without sotp the timer
console.timeLog("My Timer Name");
//My Timer Name: 1898.589111328125ms
alert("Click to continue again...");
//log time and stop timer
console.timeEnd("My Timer Name");
//My Timer Name: 2641.26123046875ms
For more information you can read official docs on MDN
Cover Image: Ansgar Koreng
Top comments (1)
Salut, Gabriele! C'est une méthode api intéressante. Et c'est vanille js. Dans d'autres langues, je préfère utiliser le gestionnaire de contexte.
Pourrais-tu m'aider s'il te plaît. J'ai besoin d'un examen de mon #showdev sur dev.to. Merci)