Posted on Updated on - Arjun

JavaScript measuring execution time

JavaScript performance is becoming increasingly important, it is good to know basic instrumentation techniques. One of the basic instrumentation tool is console.time and console.timeEnd.

console.time() starts a new timer with an associated label. When console.timeEnd() is called with the same label, the timer is stopped and the elapsed time is displayed in the console. Timer values are accurate to the sub-millisecond. The strings passed to These functions must match or else the timer will not finish.

Following is the simple example, which will show you how to measuring execution time.

Output:

JavaScript measuring execution time

Note: The only Firefox returns the elapsed time in the timeEnd() call. The other browsers simply report the result to the developer console: the return value of timeEnd() is undefined.

These functions, supported by modern browsers, in starting with Firefox11+, Chrome2+,Safari 4+ and IE11+

There are more advanced techniques for instrumentation but console.time and console.timeEnd provide a quick manual method for speed testing!

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
DMCA.com Protection Status