Created
May 17, 2012 13:11
-
-
Save gprasant/2718805 to your computer and use it in GitHub Desktop.
Write less code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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