[AskJS] Using console.time to calculate the time it takes a block of code to execute

Hi All,

I have recently become interested in the web performance side of web development. I’m wondering if the way I’m calculating the amount of time it takes a block of code to run correct and trustworthy?

Essentially what I do is wrap a console.time(), and a console.timeEnd around a block of code like so.

function copyToClipboard1(e) { console.time('Exec #1'); const clipboard = emailInput; clipboard.value = this.value; clipboard.select(); document.execCommand("copy"); console.timeEnd('Exec #1'); } 

This then returns something like this Navigator #1: 0.0869140625ms. Is this an efficient way of calculating the speed of a code block. The result each time are usually similar enough?

submitted by /u/Deviso
[link] [comments]

from 𝚓𝚊𝚟𝚊𝚜𝚌𝚛𝚒𝚙𝚝 https://ift.tt/2S6lddz

Community discussion

0 comments

Write a comment

Comments are stored with the original article on WordPress.com and protected by its moderation and spam controls. You can comment with a WordPress.com account or continue as a guest.

No comments yet. Start the conversation.