Since we don't have the outer loop code I am taking a stab in the dark here. If you are just measuring overall average runtime you don't need to store the tasks, you could use something like this to measure serial and parallel versions:
var iterations = 100;
var stopwatch = new Stopwatch();
// Run Serial version
stopwatch.Start();
for(int i = 0; i < iterations; i++)
{
for (int i = 0; i < 4; i++)
{
Console.WriteLine(tmp);
}
}
stopwatch.Stop();
var serialTime = stopwatch.ElapsedMilliseconds;
stopwatch.Reset();
// Run parallel version
stopwatch.Start();
for(int i = 0; i < iterations; i++)
{
Parallel.For(0,4, (i) => Console.WriteLine(i));
}
stopwatch.Stop();
var parallelTime = stopwatch.ElapsedMilliseconds;
Console.WriteLine("Serial took : {0}ms", serialTime / (double)iterations);
Console.WriteLine("Parallel took: {0}ms", parallelTime / (double)iterations);
This may not be a great test for measuring speedup since the workload is so light. You could try calling a function with more overhead or something like Thread.Sleep
to imitate more work. Also see my answer at This StackOverflow Question for how to measure Amdahl's Law speedup in C#.