I’m doing some performance profiling on a web app, and I’d like to be able to see how long it takes to execute sections of code.
I’m doing this by printing a date object to the console.
I can’t seem to get the date object to print its time more precisely than down to the second. Is this possible, without going so far as to get the ms since 1970 and calculating it myself?
The
toISOString()method ofDateprovides ms resolution:Returns:
But for timing sections of code, you’re probably better off using
console.timeandconsole.timeEnd.