Ruby 2.4.0 introduced `String#unpack1`, which is faster than `String#unpack[0]`
generalmimon opened this issue · comments
Petr Pučil commented
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.