paratest

class Program
{
static void Main(string[] args)
{
long result = 0;
Stopwatch Watch = new Stopwatch();
long count = 10000;
Watch.Start();
for (long i = 0; i < count; i++) {
Thread.Sleep(1);
}
Watch.Stop();
Console.WriteLine("normal for:"+ Watch.ElapsedMilliseconds);
Stopwatch Watch1 = new Stopwatch();
Watch1.Start();
result = 0;
Parallel.For(0, count,item => {
// Console.WriteLine(item);
Thread.Sleep(1);
});
Console.WriteLine("paral for:" + Watch1.ElapsedMilliseconds);
Console.ReadLine();

}
}

原文地址:https://www.cnblogs.com/stanley107/p/8854304.html