File: bench_struct_size.rb

package info (click to toggle)
ruby-ffi 1.12.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,652 kB
  • sloc: ruby: 8,078; ansic: 7,157; xml: 151; sh: 51; makefile: 14
file content (31 lines) | stat: -rw-r--r-- 664 bytes parent folder | download | duplicates (3)
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
26
27
28
29
30
31
require_relative 'bench_helper'

module BenchStructSize
  iter = ITER

  layout = class TestStruct < FFI::Struct
    layout :i, :int, :p, :pointer
  end

  puts "Benchmark FFI Struct class size performance, #{iter}x"
  10.times {
    puts Benchmark.measure {
      iter.times { TestStruct.size }
    }
  }

  s = TestStruct.new(FFI::MemoryPointer.new(TestStruct))
  puts "Benchmark FFI Struct instance size performance, #{iter}x"
  10.times {
    puts Benchmark.measure {
      iter.times { s.size }
    }
  }

  puts "Benchmark FFI Struct layout size performance, #{iter}x"
  10.times {
    puts Benchmark.measure {
      iter.times { layout.size }
    }
  }
end