Skip to content

Instantly share code, notes, and snippets.

@Nucs
Created July 5, 2019 13:25
Show Gist options
  • Select an option

  • Save Nucs/fc36822e132d7dfa1d4a3e5fd961b222 to your computer and use it in GitHub Desktop.

Select an option

Save Nucs/fc36822e132d7dfa1d4a3e5fd961b222 to your computer and use it in GitHub Desktop.
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
[SimpleJob(launchCount: 1, warmupCount: 3, targetCount: 15)]
public class ParallelFor {
private const int iterations = 10;
private int largeSize = 50_000;
DArray<int> a;
DArray<int> b;
private ParallelOptions settingsDistributed;
private ParallelOptions settingsConcurrent;
[GlobalSetup]
public void GlobalSetup() {
if (DistributedScheduler.Created == false) {
DistributedScheduler.Configure(1, 2);
}
var dist = DistributedScheduler.Default;
settingsDistributed = new ParallelOptions() {TaskScheduler = DistributedScheduler.Default, MaxDegreeOfParallelism = dist.MaximumConcurrencyLevel};
settingsConcurrent = new ParallelOptions() {TaskScheduler = TaskScheduler.Default, MaxDegreeOfParallelism = dist.MaximumConcurrencyLevel};
}
[IterationSetup]
public void Setup() {
a = new DArray<int>(new Shape(5, 5), 0);
b = new DArray<int>(Enumerable.Range(0, 25).ToArray(), new Shape(5, 5));
var _ = DArray<int>.TypeCode;
}
[Benchmark]
public void DistributedScheduler_() {
Parallel.For(0, largeSize, settingsDistributed, i => {
var c = a + b;
});
}
[Benchmark]
public void DefaultHigherDegree() {
Parallel.For(0, largeSize, settingsConcurrent, i => {
var c = a + b;
});
}
[Benchmark(Baseline = true)]
public void Default() {
Parallel.For(0, largeSize, i => {
var c = a + b;
});
}
[Benchmark()]
public void Linear() {
for (var i = 0; i < largeSize; i++) {
var c = a + b;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment