dotnet / BenchmarkDotNet

Powerful .NET library for benchmarking
https://benchmarkdotnet.org
MIT License
10.47k stars 962 forks source link

Support for running in-process in the same original thread #2589

Open Youssef1313 opened 2 months ago

Youssef1313 commented 2 months ago

https://github.com/dotnet/BenchmarkDotNet/blob/01d9b7889e13cf756068985275a3997217e4a102/src/BenchmarkDotNet/Toolchains/InProcess/NoEmit/InProcessNoEmitExecutor.cs#L59

Currently, benchmarks always run on background thread. It would be great if a new Toolchain and Executor are run on the same thread, or a property is added to existing toolchains/executors to control whether a background thread is created or not.

moritz-mg commented 2 months ago

Actually, just came across this today - we need to benchmark with a native database ORM (Realm), which requires that its instance is created on the same thread that runs the code. This fails with benchmarkdotnet as-is right now.

timcassell commented 2 months ago

Actually, just came across this today - we need to benchmark with a native database ORM (Realm), which requires that its instance is created on the same thread that runs the code. This fails with benchmarkdotnet as-is right now.

Can't you just set it up in [GlobalSetup] (and tear it down in [GlobalCleanup])?

adamsitnik commented 2 months ago

This fails with benchmarkdotnet as-is right now.

With the default toolchain no threads are being created and every benchmark is executed in a dedicated, standalone process.