Output of conventional 'for' loop. Results are displayed on order as execution happens in sequence.
Output of 'Parallel.For' loop on quad core machine. Results are out of order as execution happens in parallel.
There are three important parts to this code -first is the code that calculates and displays time of execution. This code again has three parts, first it gets current time (before execution) via following code:
DateTime T = DateTime.Now; Console.WriteLine(T)
After these lines, add your code for which you want to calculate processing time, then again get current time (after execution) and finally subtract two to get time elapsed in execution. Second important part of the sample code is conventional 'for' loop. In this loop, every iteration is executed in sequence. Finally third part of the code is 'Parallel.For' loop, where 'for' loop is executed in parallel using multiple cores of machine. As one can see 'Parallel.For' loop takes three arguments, first two arguments specify the iteration limits with last argument being delegate expression.
Results When we compared time of execution of the same code, we found out that conventional 'for' loop was able to execute in 100 seconds. When we executed 'Parallel.For' loop in dual core machine, execution time was 25 seconds while that for quad core machine was just 11 seconds. These results show how one can boost application performance using Task Parallel Library present in .NET Framework
Get most out of your technology infrastructure investments with Dell
About CIOL | Media Kit | Site Map | Contact Us | Help | Write to us | Jobs@CyberMedia | Privacy Policy
Copyright © CyberMedia India Online Ltd. All rights reserved. Usage of content from web site is subject to Terms and Conditions.