uucore: num_format: Optimize format_float_shortest
#8444
Merged
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.
Optimizing for the
%g
printf format. I don't particularly care about the usecase below, but I'm thinking of movingod
to the common formatter, where those optimizations would be welcome.We're still 20% away from coreutils, but this picks some of the low hanging fruits.
uucore: num_format: Optimize format_float_shortest
We already know the String length ahead of time, and we can
avoid using
format
.Saves about ~30% performance on:
uucore: num_format: Reduce calls to with_prec
with_prec is actually really expensive, so it's much better to
just call it once, and handle the rounding corner case manually.
Saves about ~20% performance on:
uucore: num_format: Move common scientific formatting code to a function
Both format_float_scientific and format_float_shortest carry the
same code, moving it to a single function will make it possible
to optimize both.