/// <summary>Executes the specified benchmark.</summary> public ExecuteResult Execute(ExecuteParameters executeParameters) { // TODO: preallocate buffer for output (no direct logging)? var hostLogger = LogOutput ? executeParameters.Logger : NullLogger.Instance; var host = new InProcessHost(executeParameters.BenchmarkCase, hostLogger, executeParameters.Diagnoser); int exitCode = -1; var runThread = new Thread(() => exitCode = ExecuteCore(host, executeParameters)); if (executeParameters.BenchmarkCase.Descriptor.WorkloadMethod.GetCustomAttributes <STAThreadAttribute>(false).Any()) { runThread.SetApartmentState(ApartmentState.STA); } runThread.IsBackground = true; var timeout = HostEnvironmentInfo.GetCurrent().HasAttachedDebugger ? UnderDebuggerTimeout : ExecutionTimeout; runThread.Start(); if (!runThread.Join((int)timeout.TotalMilliseconds)) { throw new InvalidOperationException( $"Benchmark {executeParameters.BenchmarkCase.DisplayInfo} takes to long to run. " + "Prefer to use out-of-process toolchains for long-running benchmarks."); } return(GetExecutionResult(host.RunResults, exitCode, executeParameters.Logger, executeParameters.BenchmarkCase.Config.Encoding)); }
public ExecuteResult Execute(ExecuteParameters executeParameters) { var hostLogger = LogOutput ? executeParameters.Logger : NullLogger.Instance; var host = new InProcessHost(executeParameters.BenchmarkCase, hostLogger, executeParameters.Diagnoser); int exitCode = 0; // The class is internal typeof(InProcessNoEmitToolchain).Assembly.GetType("BenchmarkDotNet.Toolchains.InProcess.NoEmit.InProcessNoEmitRunner").GetMethod("Run").Invoke(null, new object [] { host, executeParameters.BenchmarkCase }); return(GetExecutionResult(host.RunResults, exitCode, executeParameters.Logger, executeParameters.BenchmarkCase.Config.Encoding)); }