<story><title>Google Closure: How not to write JavaScript</title><url>http://blogs.sitepoint.com/2009/11/12/google-closure-how-not-to-write-javascript/</url><text></text></story><parent_chain><item><author>jrockway</author><text>My feeling is that even the compilers written in CS101 will optimize this.  I&apos;m guessing that Google tested their code with V8, performance was fine, and they thought nothing of it.&lt;p&gt;I just did a benchmark with node.js.  I made a 50000000 element array, and timed how long each way took.&lt;p&gt;Trial one:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    for( var i = 0; i &amp;#60; array.length; i++ ) { array[i]++ }
&lt;/code&gt;&lt;/pre&gt;
That took, on average, 0.93001866 seconds.&lt;p&gt;Trial two:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    for( var i = 0; i &amp;#60; len; i++ ) { array[i]++ }
&lt;/code&gt;&lt;/pre&gt;
That took, on average, 0.809920 seconds.&lt;p&gt;A lot of stressing-out over what ends up being a rounding error.</text></item></parent_chain><comment><author>shazow</author><text>A rounding error that causes a fast-paced Javascript game to crawl to a laggy stutter when repeated all over the place.&lt;p&gt;Regardless, the Closure Compiler (that the Closure Library is made to be used for) fixes this common case.&lt;p&gt;Another example where it&apos;s more than a rounding error: &lt;a href=&quot;http://stackoverflow.com/questions/2573212/why-is-setting-html5s-canvaspixelarray-values-ridiculously-slow-and-how-can-i-do&quot; rel=&quot;nofollow&quot;&gt;http://stackoverflow.com/questions/2573212/why-is-setting-ht...&lt;/a&gt;</text></comment>
<story><title>Google Closure: How not to write JavaScript</title><url>http://blogs.sitepoint.com/2009/11/12/google-closure-how-not-to-write-javascript/</url><text></text></story><parent_chain><item><author>jrockway</author><text>My feeling is that even the compilers written in CS101 will optimize this.  I&apos;m guessing that Google tested their code with V8, performance was fine, and they thought nothing of it.&lt;p&gt;I just did a benchmark with node.js.  I made a 50000000 element array, and timed how long each way took.&lt;p&gt;Trial one:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    for( var i = 0; i &amp;#60; array.length; i++ ) { array[i]++ }
&lt;/code&gt;&lt;/pre&gt;
That took, on average, 0.93001866 seconds.&lt;p&gt;Trial two:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    for( var i = 0; i &amp;#60; len; i++ ) { array[i]++ }
&lt;/code&gt;&lt;/pre&gt;
That took, on average, 0.809920 seconds.&lt;p&gt;A lot of stressing-out over what ends up being a rounding error.</text></item></parent_chain><comment><author>msg</author><text>Or a 13/80 difference, which is in the 15%+ range. It&apos;s a rounding error on a total time of many seconds, but not in the realm of the very fast.</text></comment>