I need to get execution time in milliseconds.
Note: I originally asked this question back in 2008. The accepted answer then was to use new Date().getTime()
However, we can all agree now that using the standard performance.now()
API is more appropriate. I am therefore changing the accepted answer to this one.
Best Answer
Using performance.now():
importing performance
Using console.time: (living standard)
Note:
The string being passed to the
time()
andtimeEnd()
methods must match(for the timer to finish as expected).