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

Ruby 2.4.0 introduced String#unpack1, which is faster than String#unpack[0] #8

Open
generalmimon opened this issue Feb 19, 2022 · 0 comments

Comments

@generalmimon
Copy link
Member

generalmimon commented Feb 19, 2022

We're probably not ready to end support for Ruby versions older than 2.4 (yet), but when we are, we could make methods for reading integers faster by switching to String#unpack1 - see https://github.com/fastruby/fast-ruby#stringunpack1-vs-stringunpack0-code:

Comparison:
      String#unpack1:  4864467.2 i/s
    String#unpack[0]:  3777815.6 i/s - 1.29x  slower

According to the above benchmark, String#unpack1 may be 29% faster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant