You want to measure how long a certain piece of code executes. In order to do so, it is enough to precede the code fragment with:
- the command
console.time("counter")
and end withconsole.timeEnd("counter")
. - the command
console.time("start")
and end withconsole.time("end")
. - the command
console.timeStart("counter")
and end withconsole.timeEnd("counter")
. - the command
timeStart()
and end withtimeEnd().
Explanation & Hint:
To measure the execution time of a code fragment in JavaScript, you can use the console.time() and console.timeEnd() methods. Precede the code fragment with console.time(“counter”). End the code fragment with console.timeEnd(“counter”). |