-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Implement fast_float
for String#to_f
#15195
base: master
Are you sure you want to change the base?
Conversation
6e96919
to
2f10232
Compare
I also added shard for this: https://github.com/kostya/fast_to_f |
I'm not sure "how" to review this, I am not qualified to review the implementation, but it passes the test suite so I have 0 doubt that it is correct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as @RX14: I don't know where to even start reviewing this, so I trust the specs.
def with_hardware_rounding_mode(mode, &) | ||
old_mode = LibC.fegetround | ||
LibC.fesetround(mode) | ||
yield ensure LibC.fesetround(old_mode) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Resolves #11952.
This is a source port of https://github.com/fastfloat/fast_float, which is both locale-independent and platform-independent, meaning the special float values will work on MSYS2's MINGW64 environment too, as we are not calling
LibC.strtod
anymore. Additionally, non-ASCII whitespace characters are now stripped, just like#to_i
.The current implementation doesn't accept hexfloats.
Below is a basic benchmark that converts random
Float32
strings:Before:
After:
Thus fast_float brings the time down from 6.23ms to 2.05ms, a roughly 3x speedup, without any additional allocations.