Tony Johansson <jo*****************@telia.comwrote:
Hello!
No
Okay, well I'm happy to write the test instead:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
class Test
{
const int Iterations = 100;
const int Size = 10000000;
static void Main()
{
// Comment out the one you don't want to use
// ArrayList list = new ArrayList(Size);
List<bytelist = new List<byte>(Size);
Stopwatch sw = Stopwatch.StartNew();
for (int i=0; i < Size; i++)
{
list.Add((byte) i);
}
int total = 0;
for (int i=0; i < Iterations; i++)
{
foreach (byte b in list)
{
total += b;
}
}
sw.Stop();
Console.WriteLine("Total = {0}", total);
Console.WriteLine("Time = {0}ms", sw.ElapsedMilliseconds);
}
}
Results:
For List<T>: around 8 seconds
For ArrayList: around 22 seconds
Oh, and originally I had Size ten times larger, but that caused
swapping with ArrayList - but not with List<T>.
--
Jon Skeet - <sk***@pobox.com>
Web site:
http://www.pobox.com/~skeet
Blog:
http://www.msmvps.com/jon.skeet
C# in Depth:
http://csharpindepth.com