:)
So, for the sake of another one of those big arguments over what's better
where no one ever test, I wrote some code to find out exact results:
The following code executes one particular test on my Windows XP machine.
For results I got an averate of 347 miliseconds executeing the --i -(-1) and
343 ms with the for..in loop. I was surprised at how close they were. Now
that being the difference over 10,000 iterations, I can't really say for..in
is much faster, if at all. Perhaps the results are different on someone
else's machine, or perhaps different results from a different type of array.
Now iterating through the entire array the for..in did seem to be faster,
but for the test I chose a value directly in the middle so each method had
the same amount of value's to cover. anyway, I conclude nothing. ;)
except that we should always test our results.
Tyler
var myArray:Array = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p"];
var time:Number = getTimer();
var loop:Number = 9999;
while (loop--)
{
/*/
var j:Number = myArray.length
while (--j -(-1)) {
if(myArray[j] == "h"){
break;
}
}
/*/
for (var j in myArray)
{
if (myArray[j] == "h")
break;
}
//*/
}
trace(getTimer() - time);
// 347
// 343
On 9/19/06, Merrill, Jason <[EMAIL PROTECTED]> wrote:
>>>>using a for..i..in loop will always be faster. Even more then --a
-(-1)
I'm ducking and running for cover.
Jason Merrill
Bank of America
Learning & Organization Effectiveness - Technology Solutions
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com