How to detect time in js in microseconds? In particular, I need to summarize the execution time of a piece of code that runs quickly (less than 1 millisecond), but often.
To measure time in microseconds (not milliseconds), you need to use the standard function
performance.now() . It returns a real number (time from the start of the process execution) in milliseconds, and the fractional part is, respectively, microseconds.
var time = performance.now(); // некий код time = performance.now() - time; console.log('Время выполнения = ', time);
You can also use
console.timeEnd('mark') – but here it will not be possible to output to the console and sum up the received time intervals.