Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A quick "benchmark" run on an average PC (i know there are lots of unaccounted-for variables, so dont comment on the obvious, but it's interesting in any case):</p> <pre><code>count = 0; t1 = +new Date(); while(count &lt; 1000000) { p = function(){}; ++count; } t2 = +new Date(); console.log(t2-t1); // milliseconds </code></pre> <p>It could be optimised by moving the increment to the condition for example (brings running time down by about 100 milliseconds, although it doesn't affect the <em>difference</em> between with and without function creation, so it isn't really relevant)</p> <p>Running 3 times gave:</p> <pre><code>913 878 890 </code></pre> <p>Then comment out the function creation line, 3 runs gave:</p> <pre><code>462 458 464 </code></pre> <p>So purely on 1000,000 empty function creations you add about half a second. Even assuming your original code is running 10 times a second on a handheld device (let's say that devices overall performance is 1/100 of this laptop, which is exaggerated - it's probably closer to 1/10, although will provide a nice upper bound), that's equivalent to 1000 function creations/sec on this computer, which happens in 1/2000 of a second. So every second the handheld device is adding overhead of 1/2000 second of processing... half a millisecond every second isn't very much.</p> <p>From this primitive test I would conclude that on a PC this is definitely a micro-optimisation, and if you're developing for weaker devices, it is almost certainly as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload