[Mono-list] foreach issues
Sat, 10 Apr 2004 17:52:46 -0500
The collection sizes and run times are so small that I question whether this
is a valid comparison. As the size of the collection increases, some of
mechanisms become much, much slower. For example, with 40,000 instead of 1000
elements, I get the times
foreach list: : 00:00:00.1349930
foreach array: : 00:00:00.0061260
IEnumerable list : 00:00:00.1076430
IEnumerable array : 00:00:00.1416560
On Saturday 10 April 2004 3:18 am, Pedro Santos wrote:
> Hi, I was wondering what would be faster when using foreach: an
> ArrayList ou an Array. At first, would be expected that foreach with an
> ArrayList would be slower than with an array, and it is a lot slower.
> But, doesn't foreach see the Array and the ArrayList has a IEnumerable?
> Whouldnt it be the same in the foreach prespective?
> It appears not to be, If I do the same, but pass an IEnumerable to the
> foreach it is alot faster, in this case the foreach with the ArrayList
> is faster.
> The test is in attachement. This were the times:
> bash-2.05b$ mono test.exe
> foreach list: : 00:00:00.0159550
> foreach array: : 00:00:00.0000420
> IEnumerable list : 00:00:00.0000830
> IEnumerable array : 00:00:00.0001040
> Can someonte elaborate on this? I am curious.