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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
require File.expand_path(File.join(File.dirname(__FILE__), "bench_helper"))
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench, :bench_PP_v, [ :buffer_in, :buffer_in ], :void
end
puts "Benchmark [ :buffer_in, :pointer ], :void performance, #{ITER}x calls"
ptr = FFI::MemoryPointer.new :int
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench(ptr, ptr) }
}
}
puts "Benchmark [ :buffer_in, :buffer_in ], :void with Struct parameters performance #{ITER}x calls"
class TestStruct < FFI::Struct
layout :i, :int
end
s = TestStruct.new(FFI::MemoryPointer.new(TestStruct));
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench(s, s) }
}
}
puts "Benchmark [ :buffer_in, :buffer_in ], :void with nil parameters performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench(nil, nil) }
}
}
puts "Benchmark [ :buffer_in, :buffer_in ], :void with Buffer parameters performance, #{ITER}x calls"
ptr = FFI::Buffer.new(:int)
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench(ptr, ptr) }
}
}
puts "Benchmark [ :buffer_in, :buffer_in ], :void with one nil, one Buffer parameter performance, #{ITER}x calls"
ptr = FFI::Buffer.new(:int)
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench(nil, ptr) }
}
}
puts "Benchmark [ :buffer_in, :buffer_in ], :void with loop-allocated Buffer parameters performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench(FFI::Buffer.new(:int), FFI::Buffer.new(:int)) }
}
}
puts "Benchmark [ :buffer_in, :buffer_in ], :void with loop-allocated MemoryPointer parameters performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench(FFI::MemoryPointer.new(:int), FFI::MemoryPointer.new(:int)) }
}
}
|