kaitai_struct_ruby_runtime
kaitai_struct_ruby_runtime copied to clipboard
Ruby 2.4.0 introduced `String#unpack1`, which is faster than `String#unpack[0]`
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.
We can do selective method definition based off Ruby version. Let me give it a try.