Skip to content

Instantly share code, notes, and snippets.

@benaadams
Created December 25, 2017 00:00
Show Gist options
  • Select an option

  • Save benaadams/73fedf79313a90bdef4f4f617cbb7aa8 to your computer and use it in GitHub Desktop.

Select an option

Save benaadams/73fedf79313a90bdef4f4f617cbb7aa8 to your computer and use it in GitHub Desktop.
ExecutionContext.Run Test
using System.Threading;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
namespace ExecutionContextTest
{
[Config(typeof(InProcConfig))]
public class Program
{
private const int OperationsPerInvoke = 1000;
static void Main(string[] args)
{
BenchmarkRunner.Run<Program>();
}
[Benchmark(OperationsPerInvoke = OperationsPerInvoke)]
public static void Run()
{
var ec = ExecutionContext.Capture();
for (var i = 0; i < OperationsPerInvoke; i++)
{
ExecutionContext.Run(ec, (o) => { }, null);
}
}
}
public class InProcConfig : ManualConfig
{
public InProcConfig()
{
Add(Job.InProcess
.WithId("InProcess"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment