Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize EnsureCapacity #228

Merged
merged 3 commits into from
Jan 25, 2025

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.

@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