I suppose you mesure with foreach?
foreach(object o in list)
{
// do something?
}
well it expands to this code:
for( IEnumerator e = list.GetEnumerator(); e.MoveNext(); )
{
object o = e.Current;
// do something
}
where
e.MoveNext() ~= return internalIndex ++ < list.Count;
e.Current ~= list[internalIndex];
which do a few more methods call compare to this one:
for(int i=0; i<Count; i++)
{
object o = list
;
// do something
}
However I think the "performance" difference the 2 becomes more and more
marginal with the complexity of the code inside the loop.
So, unless you do a simple computation, I wouldn't worry.
If you do a simple computation and you have an ArrayList of value type,
say
int you add boxing/unboxing operation "cost" (very marginal but you seems
to
care about the 0.001% of the optimizable code).
you will be better using
int[] or, in 2.0 List<int>
--
If you're in a war, instead of throwing a hand grenade at the enemy,
throw
one of those small pumpkins. Maybe it'll make everyone think how stupid
war
is, and while they are thinking, you can throw a real grenade at them.
Jack Handey.
nickdu said:
From the tests that I have done it appears the ArrayList IEnumerator is
about
three times slower than using it's IList indexer. I would think they
should
be roughly the same. Is there a reason they're not?