यह निम्न परीक्षण कार्यक्रम के लिए squat ऐसा प्रतीत नहीं होता है। क्या ऐसा इसलिए है क्योंकि मैं एक छोटी सूची के साथ परीक्षण कर रहा हूं?AsParallel वास्तव में कैसे काम करता है?
static void Main(string[] args)
{
List<int> list = 0.UpTo(4);
Test(list.AsParallel());
Test(list);
}
private static void Test(IEnumerable<int> input)
{
var timer = new Stopwatch();
timer.Start();
var size = input.Count();
if (input.Where(IsOdd).Count() != size/2)
throw new Exception("Failed to count the odds");
timer.Stop();
Console.WriteLine("Tested " + size + " numbers in " + timer.Elapsed.TotalSeconds + " seconds");
}
private static bool IsOdd(int n)
{
Thread.Sleep(1000);
return n%2 == 1;
}
दोनों संस्करणों को चलाने के लिए 4 सेकंड लगते हैं।
आप एक विस्तार विधि तक कैसे पहुंचे? – thewpfguy