-
-
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
Implement fast_float
for String#to_f
#15195
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.
def self.is_integer?(c : UC) : Bool forall UC | ||
!(c > '9'.ord || c < '0'.ord) | ||
end |
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.
thought: I suppose UC
is variable/generic in the original implementation. But this port only supports UInt8
, so I'm wondering whether making that explicit in the method signature would be better...?
OTOH I see no big downside of keeping this generic, and staying in sync with upstream could be useful.
Do we have any plans to potentially add other implementations in the future, though?
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.