<br><br>
<div><span class="gmail_quote">2006/6/28, Nick Fitzsimons <<a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:nick@nickfitz.co.uk" target="_blank">nick@nickfitz.co.uk</a>>:</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><<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>><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> </div>
<div> </div>
<div>
<p>Interesting indeed, I get 20000 tests: 32719ms for strings and 891ms for arrays in IE.<br>FF gives me 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('<option value="',values[i],'">',values[i],'</option>');<br>IE 750ms, FF 703ms.</p>
<p>Test 2<br>options.push('<option value="'+values[i]+'">'+values[i]+'</option>');<br>IE 812ms, FF 516ms.</p>
<p>Test 3<br>options.push(['<option value="'+values[i]+'">'+values[i]+'</option>'].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 < values.length; i++) {<br> options[i]=['<option value="'+values[i]+'">'+values[i]+'</option>'].join();
<br>}<br>return options.join("");<br>IE 1250ms, FF 703ms.</p>
<p>Test 5<br>Same as Test 4 but:<br>options[i]=['<option value="'+values[i]+'">'+values[i]+'</option>'].join();<br>IE 1047ms, FF 687-703ms.</p>
<p>Test 6<br>for (var i = 0; i < values.length; i++) {<br> values[i]=['<option value="'+values[i]+'">'+values[i]+'</option>'].join();<br>}<br>return values.join("");<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 one 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 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>