BenchmarkDotNet icon indicating copy to clipboard operation
BenchmarkDotNet copied to clipboard

Support for running in-process in the same original thread

Open Youssef1313 opened this issue 1 year ago • 3 comments

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.

Youssef1313 avatar Jul 15 '24 10:07 Youssef1313

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.

moritz-mg avatar Jul 16 '24 14:07 moritz-mg

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])?

timcassell avatar Jul 16 '24 19:07 timcassell

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.

adamsitnik avatar Jul 18 '24 08:07 adamsitnik