Skip to content

Conversation

@Joy-less
Copy link
Contributor

In this pull request I removed Grow and used EnsureCapacity instead. I replaced the while loop to get to the new capacity with a math algorithm.

Old

Method Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
DotNetStringBuilder 19.96 us 0.363 us 0.544 us 1.00 0.04 9.4604 29.08 KB 1.00
ValueStringBuilder 126.99 us 0.726 us 0.643 us 6.37 0.17 4.8828 15.24 KB 0.52

New

Method Mean Error StdDev Ratio RatioSD Gen0 Allocated Alloc Ratio
DotNetStringBuilder 18.14 us 0.170 us 0.159 us 1.00 0.01 9.4604 29.08 KB 1.00
ValueStringBuilder 117.62 us 0.376 us 0.351 us 6.49 0.06 4.8828 15.24 KB 0.52

@Joy-less
Copy link
Contributor Author

This is a very small optimization if at all I think but it's simpler so that's good.

@sonarqubecloud
Copy link

@linkdotnet linkdotnet merged commit f3f4759 into linkdotnet:main Jan 25, 2025
3 checks passed
@Joy-less Joy-less deleted the optimize-ensure-capacity branch January 25, 2025 12:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants