summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortduehr <tduehr@gmail.com>2014-06-24 09:26:36 -0500
committertduehr <tduehr@gmail.com>2014-06-24 09:26:36 -0500
commitdab9db4862d464c9422fa454aa4afa138f4f68fe (patch)
tree820fdac6299a674442ca0415471fc2eddd32cfcc
parentd65b1b16db9c4f294098861598b6a14dfa1c6f93 (diff)
downloadffi-dab9db4862d464c9422fa454aa4afa138f4f68fe.tar.gz
update/correct benchmarks
-rw-r--r--Rakefile1
-rw-r--r--bench/bench_IIIrI.rb8
-rw-r--r--bench/bench_SrV.rb13
-rw-r--r--bench/bench_VrV.rb21
-rw-r--r--bench/bench_buffer_alloc.rb10
-rw-r--r--bench/bench_buffer_fill.rb2
-rw-r--r--bench/bench_chmod.rb6
-rw-r--r--bench/bench_getlogin.rb1
-rw-r--r--bench/bench_getuid.rb9
-rw-r--r--bench/bench_memptr_fill.rb2
-rw-r--r--bench/bench_struct_field.rb13
-rw-r--r--ext/ffi_c/Struct.c1
12 files changed, 14 insertions, 73 deletions
diff --git a/Rakefile b/Rakefile
index b4cad6b..421f4d6 100644
--- a/Rakefile
+++ b/Rakefile
@@ -11,6 +11,7 @@ require 'date'
require 'fileutils'
require 'rbconfig'
require 'rspec/core/rake_task'
+require 'rubygems/package_task'
RSpec::Core::RakeTask.new(:spec => :compile) do |config|
config.rspec_opts = YAML.load_file 'spec/spec.opts'
diff --git a/bench/bench_IIIrI.rb b/bench/bench_IIIrI.rb
index 3df3418..312f8c0 100644
--- a/bench/bench_IIIrI.rb
+++ b/bench/bench_IIIrI.rb
@@ -15,11 +15,3 @@ puts "Benchmark [ :int, :int, :int ], :void performance, #{ITER}x calls"
}
}
puts "Benchmark Invoker.call [ :int, :int, :int ], :void performance, #{ITER}x calls"
-
-invoker = FFI.create_invoker(LIBTEST_PATH, 'bench_s32s32s32_v', [ :int, :int, :int ], :void)
-10.times {
- puts Benchmark.measure {
- ITER.times { invoker.call(0, 1, 2) }
- }
-}
-
diff --git a/bench/bench_SrV.rb b/bench/bench_SrV.rb
index 37d6593..7f4b40c 100644
--- a/bench/bench_SrV.rb
+++ b/bench/bench_SrV.rb
@@ -14,16 +14,3 @@ s = 'a' * 1000
ITER.times { LibTest.bench_S_v(s) }
}
}
-puts "Benchmark Invoker.call [ :string ], :void performance, #{ITER}x calls"
-
-invoker = FFI.create_invoker(LIBTEST_PATH, 'bench_S_v', [ :string ], :void)
-unless invoker.respond_to?("call1")
- class FFI::Invoker
- alias :call1 :call
- end
-end
-10.times {
- puts Benchmark.measure {
- ITER.times { invoker.call1(s) }
- }
-}
diff --git a/bench/bench_VrV.rb b/bench/bench_VrV.rb
index 765ff50..c5ddce6 100644
--- a/bench/bench_VrV.rb
+++ b/bench/bench_VrV.rb
@@ -3,9 +3,11 @@ require File.expand_path(File.join(File.dirname(__FILE__), "bench_helper"))
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
- attach_function :ffi_bench, :returnVoid, [ ], :void, :save_errno => false
+ attach_function :ffi_bench, :returnVoid, [ ], :void
+ attach_function :ffi_bench_noerrno, :returnVoid, [ ], :void, :save_errno => false
def self.rb_bench; nil; end
end
+
unless RUBY_PLATFORM == "java" && JRUBY_VERSION < "1.3.0"
require 'dl'
require 'dl/import'
@@ -44,28 +46,13 @@ puts "Benchmark DL void bench() performance, #{ITER}x calls"
}
}
end
-puts "Benchmark Invoker.call [ ], :void performance, #{ITER}x calls"
-
-invoker = FFI.create_invoker(LIBTEST_PATH, 'returnVoid', [ ], :int)
-10.times {
- puts Benchmark.measure {
- i = 0
- while i < ITER
- invoker.call
- i += 1
- end
- }
-}
-f = FFI::Function.new(:void, [ ], invoker, { :save_errno => false, :convention => :default })
puts "Benchmark [ ], :void no-errno performance, #{ITER}x calls"
-module NoErrno ;end
-f.attach(NoErrno, "ffi_bench")
10.times {
puts Benchmark.measure {
i = 0
while i < ITER
- NoErrno.ffi_bench
+ LibTest.ffi_bench_noerrno
i += 1
end
}
diff --git a/bench/bench_buffer_alloc.rb b/bench/bench_buffer_alloc.rb
index 9db4138..62cfc71 100644
--- a/bench/bench_buffer_alloc.rb
+++ b/bench/bench_buffer_alloc.rb
@@ -3,16 +3,6 @@ require File.expand_path(File.join(File.dirname(__FILE__), "bench_helper"))
require 'benchmark'
require 'ffi'
iter = ITER
-class Foo < FFI::Buffer
- def initialize(a1, a2, a3, a4, a5)
- puts "Foo#initialize(#{a1}, #{a2}. #{a3}, #{a4}, #{a5})"
- end
-
-end
-
-Foo.new(1, 2, 3, 4, 5)
-
-#FFI::Buffer.fubar(:int, 1, true)
puts "Benchmark Buffer.new(:int, 1, true)) performance, #{iter}x"
10.times {
diff --git a/bench/bench_buffer_fill.rb b/bench/bench_buffer_fill.rb
index 003299b..89733b8 100644
--- a/bench/bench_buffer_fill.rb
+++ b/bench/bench_buffer_fill.rb
@@ -30,7 +30,7 @@ module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
- attach_function :bench, :bench_p_v, [ :buffer_in ], :void
+ attach_function :bench, :bench_P_v, [ :buffer_in ], :void
end
puts "Benchmark Buffer alloc+fill+call performance, #{iter}x"
diff --git a/bench/bench_chmod.rb b/bench/bench_chmod.rb
index 290a30a..ea3ac37 100644
--- a/bench/bench_chmod.rb
+++ b/bench/bench_chmod.rb
@@ -7,6 +7,8 @@ file = "README"
module Posix
extend FFI::Library
+ ffi_lib FFI::Library::LIBC
+
def self.chmod(mode, path)
if self._chmod(path, mode) != 0
end
@@ -22,13 +24,13 @@ end
puts "Benchmark FFI chmod performance, #{iter}x changing mode"
10.times {
puts Benchmark.measure {
- iter.times { Posix.chmod(0622, file) }
+ iter.times { Posix.chmod(0622, __FILE__) }
}
}
puts "Benchmark Ruby File.chmod performance, #{iter}x changing mode"
10.times {
puts Benchmark.measure {
- iter.times { File.chmod(0622, file) }
+ iter.times { File.chmod(0622, __FILE__) }
}
}
diff --git a/bench/bench_getlogin.rb b/bench/bench_getlogin.rb
index 5504f71..4fabf8c 100644
--- a/bench/bench_getlogin.rb
+++ b/bench/bench_getlogin.rb
@@ -6,6 +6,7 @@ iter = 1000000
module Posix
extend FFI::Library
+ ffi_lib FFI::Library::LIBC
attach_function :getlogin, [], :string
end
if Posix.getlogin != Etc.getlogin
diff --git a/bench/bench_getuid.rb b/bench/bench_getuid.rb
index 55b0346..103069a 100644
--- a/bench/bench_getuid.rb
+++ b/bench/bench_getuid.rb
@@ -5,10 +5,10 @@ iter = 100000
module Posix
extend FFI::Library
+ ffi_lib FFI::Library::LIBC
attach_function :getuid, [], :uint
end
-
puts "uid=#{Process.pid} Posix.getuid=#{Posix.getuid}"
puts "Benchmark FFI getuid performance, #{iter}x calls"
@@ -17,13 +17,6 @@ puts "Benchmark FFI getuid performance, #{iter}x calls"
iter.times { Posix.getuid }
}
}
-puts "Benchmark FFI Invoker#call0() getuid performance, #{iter}x calls"
-invoker = FFI.create_invoker(nil, 'getuid', [], :uint)
-10.times {
- puts Benchmark.measure {
- iter.times { invoker.call0() }
- }
-}
puts "Benchmark Process.uid performance, #{iter}x calls"
10.times {
diff --git a/bench/bench_memptr_fill.rb b/bench/bench_memptr_fill.rb
index 9f475c3..28efd6a 100644
--- a/bench/bench_memptr_fill.rb
+++ b/bench/bench_memptr_fill.rb
@@ -30,7 +30,7 @@ module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
- attach_function :bench, :bench_p_v, [ :buffer_in ], :void
+ attach_function :bench, :bench_P_v, [ :buffer_in ], :void
end
puts "Benchmark MemoryPointer alloc+fill+call performance, #{iter}x"
diff --git a/bench/bench_struct_field.rb b/bench/bench_struct_field.rb
index 45ec7be..066dc63 100644
--- a/bench/bench_struct_field.rb
+++ b/bench/bench_struct_field.rb
@@ -22,19 +22,6 @@ puts "Benchmark FFI Struct.get(:int) performance, #{iter}x"
}
}
-puts "Benchmark FFI Struct.get(:int) using string name performance, #{iter}x"
-10.times {
- puts Benchmark.measure {
- i = 0; max = iter / 4; while i < max
- s['i']
- s['i']
- s['i']
- s['i']
- i += 1
- end
- }
-}
-
puts "Benchmark FFI Struct.put(:int) performance, #{iter}x"
10.times {
puts Benchmark.measure {
diff --git a/ext/ffi_c/Struct.c b/ext/ffi_c/Struct.c
index b8567be..c6428a2 100644
--- a/ext/ffi_c/Struct.c
+++ b/ext/ffi_c/Struct.c
@@ -289,6 +289,7 @@ struct_field(Struct* s, VALUE fieldName)
return rbField;
}
+ // TODO does this ever return anything?
rbField = rb_hash_aref(layout->rbFieldMap, fieldName);
if (rbField == Qnil) {
VALUE str = rb_funcall2(fieldName, id_to_s, 0, NULL);