Created
October 24, 2018 16:24
-
-
Save IJzerbaard/db056edd49b70f8bf06bcba5a1921274 to your computer and use it in GitHub Desktop.
Parallel.For test
This file contains 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
static void Main(string[] args) | |
{ | |
for (int j = 0; j < 10; j++) | |
{ | |
bool par = (j & 1) == 1; | |
var sw = Stopwatch.StartNew(); | |
if (par) | |
{ | |
Parallel.For(0, 4, test); | |
} | |
else | |
{ | |
test(0); | |
} | |
sw.Stop(); | |
Console.WriteLine("{0}: {1}", par ? "par" : "seq", sw.ElapsedTicks); | |
} | |
} | |
static volatile int r; | |
static void test(int x) | |
{ | |
int s = 0; | |
for (int i = 0; i < 1000000000; i++) | |
{ | |
s += x + i; | |
} | |
r = s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment