38
loading...
This website collects cookies to deliver better user experience
[RPlotExporter]
[SimpleJob(RunStrategy.ColdStart, RuntimeMoniker.Net50, baseline: true)]
public class ThreadPoolBaseliner
{
private Thread[] simpleThreadPool;
[Params(1, 2, 4, 8, 16, 32, 64, 128)] public int N;
[IterationSetup]
public void Setup() => simpleThreadPool = new Thread[N];
[Benchmark]
public void ThreadCreation() => CreateThreads(N);
[Benchmark]
public void ForLoopAddition() => LoopAdditionFor(N);
public void CreateThreads(int numberOfThreads)
{
for (int ii = 0; ii < numberOfThreads; ++ii)
{
simpleThreadPool[ii] = new Thread(() =>
{ Thread.Sleep(0); });
}
}
public void LoopAdditionFor(int numberOfIterations)
{
int total = 0;
for (int ii = 0; ii < numberOfIterations; ++ii) total += 42;
}
private class Program
{
public static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<ThreadPoolBaseliner>();
}
}
}