efficient than an array. In most of the cases that it is the hit comes in
the form of converting/creating the array. This seems natural: it should
take less time to assign a string value than to create an array. So while
using arrays may well be faster, creating and populating them can very well
be slower and balance out the timings seen.
When you do timings of JUST the loop (not including the data creation) then
it's a toss up - sometimes Arrays win, sometimes lists win - but they always
seem very close as far as I remember.
Secondly when CF loops over a list the list is tokenized (from what I've
been told just once). However when somebody loops over an Array they often
loop to "ArrayLen()" - this function is then run for EACH iteration (you can
see this by looping over a large, session-based array while adding elements
in another thread - the first page will loop to the new length, not the old
one). This slows things down. Using a proxy variable can eliminate that
lag, of course.
I'm just demonstrating that often when people say "this is faster than that"
it's not the primitive thing they're talking about their implementation of
it: even in simple testing code can often be optimized.
Thirdly, and this is where things get really fuzzy for me, if what I've been
told is correct and the list is only tokenized once when looping over it,
where is that tokenization stored? My guess is that it's stored in a
primitive array. If I'm correct (and it's only a guess) then looping over a
list is, in reality, doing (in a way) a very low-level conversion of the
list to an array then looping. So it may that the reason that looping over
a list is so fast is because looping over an array is so fast!
Lastly it may also be that you're right. CF Arrays aren't Java Arrays.
They're counted from 1, not zero. They're passed by value not by reference
(which I wish would change). I'm not sure what's under the covers to do
this "conversion". I assume, at least for looping, that it's such a small
thing that it doesn't matter, but who knows. In the end it may be
absolutely true that Java Arrays give the most performance - in Java. But
in CF it may not be true.
Jim Davis
_____
From: Joe Eugene [mailto:[EMAIL PROTECTED]
Sent: Saturday, August 07, 2004 10:59 AM
To: CF-Talk
Subject: RE: Can the following be written in cfscript?
"and cfml list loop is even more efficient than array..."
WOW!... There must be something really wrong with the CFMX Implementation of
Arrays.
That is completely backwards to Java Implementation. Bruce Eckel's (Thinking
in Java)
compares the Collection Classes and i believe mentions...
There is No Collection to beat "Primitive Java Arrays" Performance.
So what are we dealing with here? Coding backwards? Or We need Primitive
Data Types in CFMX?
Joe Eugene
-----Original Message-----
From: Samuel R. Neff [mailto:[EMAIL PROTECTED]
Sent: Friday, August 06, 2004 3:54 PM
To: CF-Talk
Subject: RE: Can the following be written in cfscript?
and cfml list loop is even more efficient than array...
Why is a list loop faster than an array loop?
http://www.rewindlife.com/archives/000056.cfm
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

