From 4ebc411cfc0a1306742748c452fac679379d1923 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 08:57:16 +0000 Subject: [PATCH 1/3] Initial plan From dcff0e9069b9871e5e90fcc27780a3c639872fbf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 09:06:37 +0000 Subject: [PATCH 2/3] Add three output-reading benchmarks to Perf_Process Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com> --- .../System.Diagnostics/Perf_Process.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/benchmarks/micro/libraries/System.Diagnostics/Perf_Process.cs b/src/benchmarks/micro/libraries/System.Diagnostics/Perf_Process.cs index 40bd73d7c0f..ec98837f561 100644 --- a/src/benchmarks/micro/libraries/System.Diagnostics/Perf_Process.cs +++ b/src/benchmarks/micro/libraries/System.Diagnostics/Perf_Process.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.InteropServices; +using System.Threading.Tasks; using BenchmarkDotNet.Attributes; using MicroBenchmarks; @@ -80,5 +82,47 @@ public void StartAndWaitForExit() p.WaitForExit(); } } + + private static readonly ProcessStartInfo s_outputStartInfo = new ProcessStartInfo() + { + FileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "cmd" : "sh", + Arguments = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) + ? "/c for /L %i in (1,1,1000) do @echo Line %i" + : "-c \"for i in $(seq 1 1000); do echo Line $i; done\"", + RedirectStandardOutput = true, + UseShellExecute = false + }; + + private static readonly DataReceivedEventHandler s_ignoreOutputLine = (sender, e) => { }; + + [Benchmark] + public void ReadOutputLineByLine() + { + using var process = new Process(); + process.StartInfo = s_outputStartInfo; + process.OutputDataReceived += s_ignoreOutputLine; + process.Start(); + process.BeginOutputReadLine(); + process.WaitForExit(); + process.OutputDataReceived -= s_ignoreOutputLine; + } + +#if NET + [Benchmark] + public async Task ReadOutputToEndAsync() + { + using Process process = Process.Start(s_outputStartInfo); + await process.StandardOutput.ReadToEndAsync(); + process.WaitForExit(); + } +#endif + + [Benchmark] + public void ReadOutputToEnd() + { + using Process process = Process.Start(s_outputStartInfo); + process.StandardOutput.ReadToEnd(); + process.WaitForExit(); + } } } From d3c0529b1fd501f4364f623638a29382b7b58b1a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Mar 2026 09:17:19 +0000 Subject: [PATCH 3/3] Address review feedback: static lambda, discard results, WaitForExitAsync Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com> --- .../micro/libraries/System.Diagnostics/Perf_Process.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/benchmarks/micro/libraries/System.Diagnostics/Perf_Process.cs b/src/benchmarks/micro/libraries/System.Diagnostics/Perf_Process.cs index ec98837f561..6f51abb8e53 100644 --- a/src/benchmarks/micro/libraries/System.Diagnostics/Perf_Process.cs +++ b/src/benchmarks/micro/libraries/System.Diagnostics/Perf_Process.cs @@ -93,7 +93,7 @@ public void StartAndWaitForExit() UseShellExecute = false }; - private static readonly DataReceivedEventHandler s_ignoreOutputLine = (sender, e) => { }; + private static readonly DataReceivedEventHandler s_ignoreOutputLine = static (sender, e) => { }; [Benchmark] public void ReadOutputLineByLine() @@ -112,8 +112,8 @@ public void ReadOutputLineByLine() public async Task ReadOutputToEndAsync() { using Process process = Process.Start(s_outputStartInfo); - await process.StandardOutput.ReadToEndAsync(); - process.WaitForExit(); + _ = await process.StandardOutput.ReadToEndAsync(); + await process.WaitForExitAsync(); } #endif @@ -121,7 +121,7 @@ public async Task ReadOutputToEndAsync() public void ReadOutputToEnd() { using Process process = Process.Start(s_outputStartInfo); - process.StandardOutput.ReadToEnd(); + _ = process.StandardOutput.ReadToEnd(); process.WaitForExit(); } }