<br><br>
<div><span class="gmail_quote">2006/6/28, Nick Fitzsimons &lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:nick@nickfitz.co.uk" target="_blank">nick@nickfitz.co.uk</a>&gt;:</span> 
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">is much faster on Internet Explorer for Windows. I've put up a test page at<br>&lt;<a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.nickfitz.co.uk/tests/javascript/strings.html" target="_blank">
 http://www.nickfitz.co.uk/tests/javascript/strings.html</a>&gt;<br>where you can try the two methods side-by-side for 1000, 10000 and 20000<br>values; 20000 takes a looong time for the first method, ~68000ms on my<br>machine versus ~1700ms for the second method. 
<br><br>Interestingly, Firefox appears to be much more heavily optimised for<br>string manipulation: on the same machine, the equivalent timings are<br>both ~1100ms.</blockquote>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>
<p>Interesting indeed, I get 20000 tests: 32719ms for strings and 891ms for arrays in IE.<br>FF gives me&nbsp; 640ms with strings vs 766ms with arrays, which is quite imressed with.<br>But most impressive is the 1000 loop tests in FF. Strings always take 0ms, arrays either 0ms or 15ms, I wonder how they pull that off...
</p>
<p>I also tried som other variants:</p>
<p>Test 1<br>options.push('&lt;option value=&quot;',values[i],'&quot;&gt;',values[i],'&lt;/option&gt;');<br>IE 750ms, FF 703ms.</p>
<p>Test 2<br>options.push('&lt;option value=&quot;'+values[i]+'&quot;&gt;'+values[i]+'&lt;/option&gt;');<br>IE 812ms, FF 516ms.</p>
<p>Test 3<br>options.push(['&lt;option value=&quot;'+values[i]+'&quot;&gt;'+values[i]+'&lt;/option&gt;'].join());<br>IE 1078ms, FF 687ms.</p>
<p>Test 4<br>var options = [values.length]; // Both browser are a few ms faster when the length is predefined.<br>for (var i = 0; i &lt; values.length; i++) {<br>&nbsp;options[i]=['&lt;option value=&quot;'+values[i]+'&quot;&gt;'+values[i]+'&lt;/option&gt;'].join();
<br>}<br>return options.join(&quot;&quot;);<br>IE 1250ms, FF 703ms.</p>
<p>Test 5<br>Same as Test 4 but:<br>options[i]=['&lt;option value=&quot;'+values[i]+'&quot;&gt;'+values[i]+'&lt;/option&gt;'].join();<br>IE 1047ms, FF 687-703ms.</p>
<p>Test 6<br>for (var i = 0; i &lt; values.length; i++) {<br>&nbsp;values[i]=['&lt;option value=&quot;'+values[i]+'&quot;&gt;'+values[i]+'&lt;/option&gt;'].join();<br>}<br>return values.join(&quot;&quot;);<br>IE 766ms,FF 672ms.
</p>
<p>We have a winner! I vote for Test 1 since Test 6 uses an extra join operation, which doesn't feel right...<br>If&nbsp;one&nbsp;stores values.length in a variable instead of checking it directly, FF goes down to about 610ms.<br>
It however doesn't seem to make a difference in IE. Things like looping backwards and&nbsp;while-looping didn't seem to make a difference at all in any of them.</p>
<p>This will change how I deal with strings for sure!</p></div></div>