summaryrefslogtreecommitdiff
path: root/benchmark/buffer_get.yml
blob: 9e1f99d64e8643df1f7abd265730a80201b5f667 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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")