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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
require_relative 'bench_helper'
module BenchBuffer
iter = ITER
module BufferBench
extend FFI::Library
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_s32_v, [ :int ], :void
begin
attach_function :bench_buffer_in, :ptr_ret_int32_t, [ :buffer_in, :int ], :void
rescue FFI::NotFoundError
# NetBSD uses #define instead of typedef for these
attach_function :bench_buffer_in, :ptr_ret___int32_t, [ :buffer_in, :int ], :void
end
begin
attach_function :bench_buffer_inout, :ptr_ret_int32_t, [ :buffer_inout, :int ], :void
rescue FFI::NotFoundError
# NetBSD uses #define instead of typedef for these
attach_function :bench_buffer_inout, :ptr_ret___int32_t, [ :buffer_inout, :int ], :void
end
begin
attach_function :bench_buffer_out, :ptr_ret_int32_t, [ :buffer_out, :int ], :void
rescue FFI::NotFoundError
# NetBSD uses #define instead of typedef for these
attach_function :bench_buffer_out, :ptr_ret___int32_t, [ :buffer_out, :int ], :void
end
end
class IntStruct < FFI::Struct
layout :i, :int
end
puts "Benchmark FFI call(MemoryPointer.new(:int, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_inout(FFI::MemoryPointer.new(:int, 1, true), 0) }
}
}
puts "Benchmark FFI call(MemoryPointer.new(4, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_inout(FFI::MemoryPointer.new(4, 1, true), 0) }
}
}
puts "Benchmark FFI call(MemoryPointer.new(IntStruct, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_inout(FFI::MemoryPointer.new(IntStruct, 1, true), 0) }
}
}
puts "Benchmark FFI call(0.chr * 4) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_inout(0.chr * 4, 0) }
}
}
puts "Benchmark FFI call(Buffer.alloc_inout(:int, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_inout(FFI::Buffer.alloc_inout(:int, 1, true), 0) }
}
}
puts "Benchmark FFI call(Buffer.alloc_inout(IntStruct, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_inout(FFI::Buffer.alloc_inout(IntStruct, 1, true), 0) }
}
}
puts "Benchmark FFI call(Buffer.alloc_inout(4, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_inout(FFI::Buffer.alloc_inout(4, 1, true), 0) }
}
}
puts "Benchmark FFI call(Buffer.alloc_in(:int, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_in(FFI::Buffer.alloc_in(:int, 1, true), 0) }
}
}
puts "Benchmark FFI call(Buffer.alloc_in(4, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_in(FFI::Buffer.alloc_in(4, 1, true), 0) }
}
}
puts "Benchmark FFI call(Buffer.alloc_in(IntStruct, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_in(FFI::Buffer.alloc_in(IntStruct, 1, true), 0) }
}
}
puts "Benchmark FFI call(Buffer.alloc_out(:int, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_out(FFI::Buffer.alloc_out(:int, 1, true), 0) }
}
}
puts "Benchmark FFI call(Buffer.alloc_out(IntStruct, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_out(FFI::Buffer.alloc_out(IntStruct, 1, true), 0) }
}
}
puts "Benchmark FFI call(Buffer.alloc_out(4, 1, true)) performance, #{iter}x"
10.times {
puts Benchmark.measure {
iter.times { BufferBench.bench_buffer_out(FFI::Buffer.alloc_out(4, 1, true), 0) }
}
}
end
|