From 6cbac641112f7e6f2e4c5ee435a35a4b84700cf7 Mon Sep 17 00:00:00 2001 From: Simon McKenna Date: Sun, 18 Oct 2026 13:05:55 +1030 Subject: [PATCH] Restore the original console writer after benchmarks run Console.SetOut(Console.Out) ran after Console.Out was already TextWriter.Null, so it restored nothing. Save the writer first, and restore it in a finally block. --- LeetCode/BenchmarkRunner.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/LeetCode/BenchmarkRunner.cs b/LeetCode/BenchmarkRunner.cs index 895cb3d..0f2820e 100644 --- a/LeetCode/BenchmarkRunner.cs +++ b/LeetCode/BenchmarkRunner.cs @@ -13,15 +13,22 @@ public static IEnumerable BuildSummaries(BenchmarkSettings settings) ConsoleWriter.MoveCursor(CursorDirection.Up); + // Silence BenchmarkDotNet's console logging while the spinner runs + var consoleOut = Console.Out; Console.SetOut(TextWriter.Null); var summaries = new List(); - AnsiConsole.Status() - .Spinner(Spinner.Known.Dots) - .Start(WaitingMessage(settings, args), _ => - summaries.AddRange(RunBenchmarks(settings.BenchmarkTypes(), args))); - - Console.SetOut(Console.Out); + try + { + AnsiConsole.Status() + .Spinner(Spinner.Known.Dots) + .Start(WaitingMessage(settings, args), _ => + summaries.AddRange(RunBenchmarks(settings.BenchmarkTypes(), args))); + } + finally + { + Console.SetOut(consoleOut); + } ConsoleWriter.MoveCursor(CursorDirection.Down);