Excution Time
Let’s explore methods for measuring JavaScript execution time.
The conventional approach involves using the getTime()
method of the Date
object to calculate time differences. The resulting value represents milliseconds.
const beginTime = new Date().getTime();
// Code to be timed
console.log(new Date().getTime() - beginTime);
Alternatively, for quick verification of processing speed during development, the console.time
and console.timeEnd
functions can be employed.
console.time
marks the starting point, and console.timeEnd
marks the ending point. The str
argument passed to both functions must have the same value. The output represents the elapsed time in milliseconds.
const timerName = "myTimer"; // Use a descriptive timer name
console.time(timerName);
// Code to be timed
console.timeEnd(timerName);
댓글남기기