2022-08-08 12:14:05 +03:00
|
|
|
prelude: |
|
|
|
|
# frozen_string_literal: true
|
|
|
|
Warning[:experimental] = false
|
2022-09-26 08:06:12 +03:00
|
|
|
string = "The quick brown fox jumped over the lazy dog."
|
|
|
|
buffer = IO::Buffer.for(string)
|
|
|
|
format = [:U32, :U32, :U32, :U32]
|
2021-07-02 13:41:16 +03:00
|
|
|
benchmark:
|
2022-08-08 12:14:05 +03:00
|
|
|
string.unpack1: |
|
2022-09-26 08:06:12 +03: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")
|