2022-08-08 05:14:05 -04:00
|
|
|
prelude: |
|
|
|
|
# frozen_string_literal: true
|
|
|
|
Warning[:experimental] = false
|
2022-09-26 01:06:12 -04:00
|
|
|
string = "The quick brown fox jumped over the lazy dog."
|
|
|
|
buffer = IO::Buffer.for(string)
|
|
|
|
format = [:U32, :U32, :U32, :U32]
|
2021-07-02 06:41:16 -04:00
|
|
|
benchmark:
|
2022-08-08 05:14:05 -04:00
|
|
|
string.unpack1: |
|
2022-09-26 01:06:12 -04:00
|
|
|
[
|
|
|
|
string.unpack1("N"),
|
|
|
|
string.unpack1("N", offset: 4),
|
|
|
|
string.unpack1("N", offset: 8),
|
|
|
|
string.unpack1("N", offset: 12),
|
|
|
|
]
|
|
|
|
buffer.get_value: |
|
|
|
|
[
|
|
|
|
buffer.get_value(:U32, 0),
|
|
|
|
buffer.get_value(:U32, 4),
|
|
|
|
buffer.get_value(:U32, 8),
|
|
|
|
buffer.get_value(:U32, 12),
|
|
|
|
]
|
|
|
|
buffer.get_values: |
|
|
|
|
buffer.get_values(format, 0)
|
|
|
|
string.unpack: |
|
|
|
|
string.unpack("NNNN")
|