Skip to content

Instantly share code, notes, and snippets.

@gprasant
Created May 17, 2012 13:11
Show Gist options
  • Save gprasant/2718805 to your computer and use it in GitHub Desktop.
Save gprasant/2718805 to your computer and use it in GitHub Desktop.
Write less code
//output :
Normal Array Elapsed Time: 10831
Parallel For Elapsed Time: 39028
Clone Elapsed Time: 2149
//code
[Test]
public void zz()
{
int[,] srcArray = new int[Byte.MaxValue,Byte.MaxValue];
int[,] destArray = new int[Byte.MaxValue,Byte.MaxValue];
Stopwatch sw = Stopwatch.StartNew();
for (int i = 0; i < Byte.MaxValue; i++)
{
for (int j = 0; j < Byte.MaxValue; j++)
{
destArray[i,j] = srcArray[i,j];
}
}
sw.Stop();
Console.WriteLine("Normal Array Elapsed Time: " + sw.Elapsed.Ticks);
sw = Stopwatch.StartNew();
Parallel.For(0, Byte.MaxValue,
i => Parallel.For(0, Byte.MaxValue,
j => destArray[i,j] = srcArray[i,j]));
sw.Stop();
Console.WriteLine("Parallel For Elapsed Time: " + sw.Elapsed.Ticks);
sw = Stopwatch.StartNew();
destArray = (int[,])srcArray.Clone();
sw.Stop();
Console.WriteLine("Clone Elapsed Time: " + sw.Elapsed.Ticks);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment