[Javascript] Single vs. Double quotes in Javascript

liorean liorean at f2o.org
Fri Nov 14 05:54:07 CST 2003


Peter-Paul Koch wrote:
>> I did not test this code to confirm or deny the 15% faster claim
> I did, and cannot confirm it. It seems that single quotes are 
> *sometimes* faster in Explorer Windows (roughly 1/3 of my tests did show 
> a faster response time), but if Mozilla shows a difference at all, it 
> handles double quotes slightly faster. I found no difference at all in 
> Opera.
> 
> I cannot say that these experiments confirm the 15% claim.

Running my own test, I achieved the following results:

(average execution time of 50 tests of an iteration over 5e4 string 
concatenations)

Single #1, moz: 108.76 ms
Single #2, moz: 109.16 ms
Double #1, moz: 107.96 ms
Double #2, moz: 109.36 ms

Single #1, op7: 121.16 ms
Single #2, op7: 122.38 ms
Double #1, op7: 119.98 ms
Double #2, op7: 121.58 ms

These were all performed under exactly the same conditions, with the 
difference being just double versus single quotes. So,

And the test:
javascript:var a=50,b=[];while(a--)b.push((function(){var i=new 
Date,t=5e4,s='';while(t--)s+='text';return (new 
Date-i);})());while(b.length>1)b[0]+=b.pop();b/=50; // Substitute single 
for double quotes to get the double quote test

(I tried to run the test code in ie6w and saf1.0 both, but the browsers 
just stopped responding each time I did that, so I have no test results 
from there...)
-- 
liorean <mailto:liorean at user.bip.net>

ViewStyles, ViewScripts, ToggleStyles and GraphicsInfo bookmarklets and 
Theme Switcher, Cookies Handler scripts:
<http://liorean.web-graphics.com/>




More information about the Javascript mailing list