>
> using join on an array of strings, which, unsurprisingly is way slower in
> this case but can be faster when joining
> many strings


I do wonder: at what point does doing array join outperform concatenation?
Would it depend only on the number of items being concatenated or does
individual element length also matter?

Brian


On Fri, Oct 14, 2011 at 4:47 PM, Andrew Hedges <[email protected]> wrote:

> Hi Jess,
>
> I'm not sure what the purpose of the consumeURL function is if you just
> want to test the speed of
> assigning/concatenating strings. I made a modified test that strips out
> that part of things and adds another test case
> (using join on an array of strings, which, unsurprisingly is way slower in
> this case but can be faster when joining
> many strings).
>
> http://jsperf.com/string-concat-vs-long-lines/2
>
> -----
> [email protected] / http://andrew.hedges.name/
>
> On Sat, October 15, 2011 9:25 am, Jess Jacobs wrote:
> > Hello everyone,
> >
> > I ran into an interesting issue while trying to prove that adding string
> > concats to a long running string simply to fit the "80 char/line" idea
> was
> > not a good thing.
> >
> > http://jsperf.com/string-concat-vs-long-lines
> >
> > I discovered, unless my tests have errors (please call 'em out if so!):
> >
> > 1. string declaration without concats is faster than concatenating two
> > strings (obviously)
> > 2. concatenating string + string is slower than concatenating var (with a
> > string value) + string (interesting)
> > 3. concatenating a var (string value) with a string is FASTER than
> declaring
> > a variable with only a string value (very interesting)
> >
> > The tests are vastly different for each browser, with Safari taking an
> > unbelievable lead in string processing over Chrome. Firefox came in dead
> > last of the three (I didn't test IE, but if someone wants to, I'm
> definitely
> > curious). Some test results differ even in which method is fastest in a
> > particular browser, but not typically by much. While the browser speed
> > differences were surprising to me, what's more surprising is item #3
> above.
> >
> > Items 1 and 2 make a lot of sense to me; 1 being obvious, 2 I'm figuring
> > could be explained by primitive type conversion possibly not having to
> > happen due to one of the concat'd items already being a String object -
> but
> > now that I think about it, aren't they both primitive types since neither
> > were created as new String(), etc? 3, however, blows my mind. How on
> earth
> > is it faster to concat a var and a string and assign it to a var than it
> is
> > to simply assign a string value to a var?
> >
> > I'd really love to get way down to the nitty gritty on this, so anyone
> with
> > any insight, your replies are appreciated. Also would love to see any
> test
> > cases (more robust than mine) that could illustrate better what exactly
> is
> > going on here.
> >
> > Thanks,
> > Jess
> >
> > ========================
> > Jess Jacobs
> > [email protected]
> > flavors.me/akisma - music, sound design, code.
> >
> > --
> > To view archived discussions from the original JSMentors Mailman list:
> > http://www.mail-archive.com/[email protected]/
> >
> > To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
> >
> > To unsubscribe from this group, send email to
> > [email protected]
> >
>
> --
> To view archived discussions from the original JSMentors Mailman list:
> http://www.mail-archive.com/[email protected]/
>
> To search via a non-Google archive, visit here:
> http://www.mail-archive.com/[email protected]/
>
> To unsubscribe from this group, send email to
> [email protected]
>

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to