7 extend JRuby::FFI::Library
8 attach_function :memchr, [ :string, :char, :int ], :pointer
13 attach_function :memchr, [ :string, :char, :int ], :pointer
16 if JLibC.memchr("test", 't', 4).nil?
17 raise ArgumentError, "JRuby::FFI.memchr returned incorrect value"
19 if RbxLibC.memchr("test", 't', 4).nil?
20 raise ArgumentError, "FFI.memchr returned incorrect value"
22 puts "Benchmark FFI memchr(3) (rubinius api) performance, #{iter}x"
24 puts Benchmark.measure {
25 iter.times { RbxLibC.memchr(str, 't', 4) }
28 puts "Benchmark FFI memchr(3) (jruby api) performance, #{iter}x"
30 puts Benchmark.measure {
31 iter.times { JLibC.memchr(str, 't', 4) }