namespace ConsoleApplication1
{
class Program
{
private const int MaxLength = 100000;
private static readonly List<int> list = new List<int>();
static void GetList()
{
int i = 0;
while (i < MaxLength)
{
list.Add(i);
i++;
}
}
static DateTime Method1()
{
for (int i = 0; i < list.Count; i++)
{
int a;
a = i ^ 100;
int b = a >> 2 << 3;
}
return DateTime.Now;
}
static DateTime Method2()
{
int size = list.Count;
for (int i = 0; i < size; i++)
{
int a;
a = i ^ 100;
int b = a >> 2 << 3;
}
return DateTime.Now;
}
static void Main()
{
GetList();
var a = DateTime.Now;
Console.WriteLine(string.Format("Method 1. Time elapsed: {0}", (Method1() - a)));
a = DateTime.Now;
Console.WriteLine(string.Format("Method 2. Time elapsed: {0}", (Method2() - a)));
Console.ReadLine();
}
}
}
надеюсь я не тупанул, хотя как оговаривалось ранее, все зависит от реализации используемого объекта.
p.s. было интересно, а будет-ли разница? Оказалось есть.
Проц Core2Duo E8400
__________________
*********************************
*Я не волшебник ٩(๏̯͡๏)۶, только учусь...*
********************************* Программы на заказ
Times to fly...
Последний раз редактировалось W!z@rD; 07.05.2009 в 20:27..