mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
25 lines
658 B
YAML
25 lines
658 B
YAML
prelude: |
|
|
# frozen_string_literal: true
|
|
Warning[:experimental] = false
|
|
string = "The quick brown fox jumped over the lazy dog."
|
|
buffer = IO::Buffer.for(string)
|
|
format = [:U32, :U32, :U32, :U32]
|
|
benchmark:
|
|
string.unpack1: |
|
|
[
|
|
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")
|