Update AddValuesToArray sample: net10.0, append methods, grow benchmark - #2207
Open
vladimir-pecanac-main wants to merge 1 commit into
Open
vladimir-pecanac-main wants to merge 1 commit into
vladimir-pecanac-main wants to merge 1 commit into
Conversation
Retarget all three projects from net8.0 to net10.0 and refresh the packages: BenchmarkDotNet 0.15.8, xunit 2.9.3 with runner 4.0.0, Microsoft.NET.Test.Sdk 18.10.0, coverlet.collector 10.0.1. Fix the benchmark's size parameter. The class held three fixed 10,000-element fields while taking arraySize as an argument, so only the two Manual methods honoured it and a 1,000-element run made ArrayCopyTo throw. Replace ArgumentsSource with [Params(1_000, 10_000)] and build the source array and list in a [GlobalSetup]. Drop the dead arraySize parameter from UsingList and update its two call sites. Trim trailing whitespace in ArrayCopyTo. Add AppendWithResize, AppendWithCollectionExpression, CollectionExpression, GrowWithResize and GrowWithList, with five tests covering them, a CollectionExpression benchmark and a new GrowBenchmark class comparing Array.Resize in a loop against List<T>.Add followed by ToArray. Run the benchmark project through BenchmarkSwitcher so either class can be selected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates the
collections-arrays/AddValuesToArraysample alongside a rewrite of the article it backs.Retarget and packages
All three projects move from
net8.0tonet10.0. BenchmarkDotNet 0.13.1 to 0.15.8,xunit2.4.1 to 2.9.3,xunit.runner.visualstudio2.4.3 to 4.0.0,Microsoft.NET.Test.Sdk17.1.0 to 18.10.0,coverlet.collector3.1.2 to 10.0.1. Versions read from NuGet on the day this PR opened. Build is clean, 0 warnings and 0 errors.Benchmark fix
AddValuesToArrayBenchmarkdeclared three fixed 10,000-element fields and then tookarraySizefromArgumentsSource, whose body yielded only10_000. Only the twoManualmethods honoured the parameter, and adding a 1,000-element case madeArrayCopyTocopy a 10,000-element source into a 1,000-element destination, which throwsArgumentException. Replaced with[Params(1_000, 10_000)]plus a[GlobalSetup]that builds the source array and the list at the parameterised size.UsingList(int arraySize, List<int> list)never readarraySize, so the parameter is dropped and its two call sites updated.New methods and tests
AppendWithResize,AppendWithCollectionExpression,CollectionExpression,GrowWithResizeandGrowWithList, each covered by a new xunit test, including one pinning thatArray.Resizeleaves any other reference on the original array. A newGrowBenchmarkclass compares resizing in a loop againstList<T>followed by oneToArray().Program.csin the benchmark project now usesBenchmarkSwitcherso either class can be selected.10 of 10 tests pass locally on SDK 10.0.302 / runtime 10.0.10.