var d = new Date();
var startTime = d.getTime();
endTime = d.getTime();
You can use
performance.now() if the engine supports it. This gives a time in milliseconds, with sub-millisecond precision, since the page loaded or app started.
performance.now() // 26742.766999999956
I know Chrome supports it, but not sure about other browsers, node.js, or other engines standalone js engines.
Or you can run your code many times in a loop, and measure the total time taken.