From 52f6387df559eaeaaf8f77149aa75e7adbd4f34d Mon Sep 17 00:00:00 2001 From: Vladimir Pecanac Date: Sun, 25 Oct 2026 13:17:30 +0100 Subject: [PATCH 1/2] PrintOutArrayElements: port to .NET 10, pass args to BenchmarkDotNet, add type-name test --- .../BenchmarkRunner/BenchmarkRunner.csproj | 4 ++-- .../BenchmarkRunner/ElementPrinterBenchmark.cs | 3 +-- .../PrintOutArrayElements/BenchmarkRunner/Program.cs | 2 +- .../PrintOutArrayElements/PrintOutArrayElements.csproj | 2 +- .../PrintOutArrayElements/Program.cs | 2 +- .../PrintOutArrayElements/Tests/Tests.cs | 10 +++++++++- .../PrintOutArrayElements/Tests/Tests.csproj | 10 +++++----- 7 files changed, 20 insertions(+), 13 deletions(-) diff --git a/collections-arrays/PrintOutArrayElements/BenchmarkRunner/BenchmarkRunner.csproj b/collections-arrays/PrintOutArrayElements/BenchmarkRunner/BenchmarkRunner.csproj index 21afcbbabf..ecddb28d53 100644 --- a/collections-arrays/PrintOutArrayElements/BenchmarkRunner/BenchmarkRunner.csproj +++ b/collections-arrays/PrintOutArrayElements/BenchmarkRunner/BenchmarkRunner.csproj @@ -2,13 +2,13 @@ Exe - net6.0 + net10.0 enable enable - + diff --git a/collections-arrays/PrintOutArrayElements/BenchmarkRunner/ElementPrinterBenchmark.cs b/collections-arrays/PrintOutArrayElements/BenchmarkRunner/ElementPrinterBenchmark.cs index f0bcae89f2..20cc338111 100644 --- a/collections-arrays/PrintOutArrayElements/BenchmarkRunner/ElementPrinterBenchmark.cs +++ b/collections-arrays/PrintOutArrayElements/BenchmarkRunner/ElementPrinterBenchmark.cs @@ -16,8 +16,7 @@ private static int[] FillElements(int length) for (int i = 0; i < length; i++) { - var value = new Random().Next(0, 1000); - array[i] = value; + array[i] = Random.Shared.Next(0, 1000); } return array; diff --git a/collections-arrays/PrintOutArrayElements/BenchmarkRunner/Program.cs b/collections-arrays/PrintOutArrayElements/BenchmarkRunner/Program.cs index fa95dd3f1c..2c18d300ea 100644 --- a/collections-arrays/PrintOutArrayElements/BenchmarkRunner/Program.cs +++ b/collections-arrays/PrintOutArrayElements/BenchmarkRunner/Program.cs @@ -1,3 +1,3 @@ using BenchmarkRunner; -BenchmarkDotNet.Running.BenchmarkRunner.Run(); \ No newline at end of file +BenchmarkDotNet.Running.BenchmarkRunner.Run(args: args); diff --git a/collections-arrays/PrintOutArrayElements/PrintOutArrayElements/PrintOutArrayElements.csproj b/collections-arrays/PrintOutArrayElements/PrintOutArrayElements/PrintOutArrayElements.csproj index 74abf5c976..dfb40caafc 100644 --- a/collections-arrays/PrintOutArrayElements/PrintOutArrayElements/PrintOutArrayElements.csproj +++ b/collections-arrays/PrintOutArrayElements/PrintOutArrayElements/PrintOutArrayElements.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net10.0 enable enable diff --git a/collections-arrays/PrintOutArrayElements/PrintOutArrayElements/Program.cs b/collections-arrays/PrintOutArrayElements/PrintOutArrayElements/Program.cs index 86de76afbd..614131fdf5 100644 --- a/collections-arrays/PrintOutArrayElements/PrintOutArrayElements/Program.cs +++ b/collections-arrays/PrintOutArrayElements/PrintOutArrayElements/Program.cs @@ -3,7 +3,7 @@ public class Program { private static readonly ElementPrinter _elementPrinter = new(); - private static readonly int[] _array = new int[] { 1, 4, 6, 7, 9, 3, 5 }; + private static readonly int[] _array = [1, 4, 6, 7, 9, 3, 5]; public static int OutPutResult = 0; public static void Main(string[] args) diff --git a/collections-arrays/PrintOutArrayElements/Tests/Tests.cs b/collections-arrays/PrintOutArrayElements/Tests/Tests.cs index 4bf20b99b8..6b6083d69b 100644 --- a/collections-arrays/PrintOutArrayElements/Tests/Tests.cs +++ b/collections-arrays/PrintOutArrayElements/Tests/Tests.cs @@ -10,7 +10,7 @@ namespace Tests public class Tests { private static readonly ElementPrinter _elementPrinter = new(); - private static readonly int[] _array = new int[] { 1, 4, 6, 7, 9, 3, 5 }; + private static readonly int[] _array = [1, 4, 6, 7, 9, 3, 5]; private const string _expectedResult = " ==> 1 ==> 4 ==> 6 ==> 7 ==> 9 ==> 3 ==> 5"; private static readonly StringBuilder _consoleOutput = new(); @@ -29,6 +29,14 @@ public void GivenTheClassProgram_WhenExecuteTheMainMethod_ThenSetTheOutPutResult Assert.AreEqual(1, Program.OutPutResult); } + [TestMethod] + public void GivenAnArray_WhenPassingItToConsoleWrite_ThenPrintOutTheTypeName() + { + Console.Write(_array); + + Assert.AreEqual("System.Int32[]", _consoleOutput.ToString()); + } + [TestMethod] public void GivenAnArray_WhenUsingForLoop_ThenPrintOutTheResultOnTheScreen() { diff --git a/collections-arrays/PrintOutArrayElements/Tests/Tests.csproj b/collections-arrays/PrintOutArrayElements/Tests/Tests.csproj index 57d19f3012..5d8603adcd 100644 --- a/collections-arrays/PrintOutArrayElements/Tests/Tests.csproj +++ b/collections-arrays/PrintOutArrayElements/Tests/Tests.csproj @@ -1,17 +1,17 @@ - net6.0 + net10.0 enable false - - - - + + + + From 6cf189d79ebf4a2748a911cb1b983f529b40a667 Mon Sep 17 00:00:00 2001 From: Vladimir Pecanac Date: Sun, 25 Oct 2026 14:58:49 +0100 Subject: [PATCH 2/2] PrintOutArrayElements: run benchmarks in process by default The default out-of-process host keeps every line the benchmarks print and runs out of memory. Program.cs adds --inProcess unless the caller already passed it. --- .../PrintOutArrayElements/BenchmarkRunner/Program.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/collections-arrays/PrintOutArrayElements/BenchmarkRunner/Program.cs b/collections-arrays/PrintOutArrayElements/BenchmarkRunner/Program.cs index 2c18d300ea..7b8b748056 100644 --- a/collections-arrays/PrintOutArrayElements/BenchmarkRunner/Program.cs +++ b/collections-arrays/PrintOutArrayElements/BenchmarkRunner/Program.cs @@ -1,3 +1,6 @@ using BenchmarkRunner; -BenchmarkDotNet.Running.BenchmarkRunner.Run(args: args); +// In-process: the default out-of-process host keeps every line the benchmarks print and runs out of memory. +string[] benchmarkArgs = args.Any(a => a is "--inProcess" or "-i") ? args : [.. args, "--inProcess"]; + +BenchmarkDotNet.Running.BenchmarkRunner.Run(args: benchmarkArgs);