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
|