summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWayne Meissner <wmeissner@gmail.com>2012-04-05 10:34:36 +1000
committerWayne Meissner <wmeissner@gmail.com>2012-04-05 10:34:36 +1000
commit64a38152d0db845c55077c1fb0287d76543c1765 (patch)
tree841015c6871ce317d38001a25dfaa68426b6dcad
parentd2cf8c991570ba3103f7e7063dfa6de0fed7009b (diff)
downloadffi-64a38152d0db845c55077c1fb0287d76543c1765.tar.gz
Some pointer/int benchmark refinements
-rw-r--r--bench/bench_PrV.rb5
-rw-r--r--bench/bench_buffer_alloc.rb7
-rw-r--r--bench/bench_closure_IrV.rb10
-rw-r--r--bench/bench_enum.rb23
-rw-r--r--bench/bench_memptr_alloc.rb17
-rw-r--r--bench/bench_strlen.rb9
6 files changed, 66 insertions, 5 deletions
diff --git a/bench/bench_PrV.rb b/bench/bench_PrV.rb
index c9ba471..3b58786 100644
--- a/bench/bench_PrV.rb
+++ b/bench/bench_PrV.rb
@@ -8,7 +8,7 @@ module LibTest
end
-puts "Benchmark [ :buffer_in ], :void performance, #{ITER}x calls"
+puts "Benchmark [ :buffer_in ], :void performance (pre allocated pointer), #{ITER}x calls"
ptr = FFI::MemoryPointer.new :int
10.times {
puts Benchmark.measure {
@@ -31,9 +31,10 @@ ptr = FFI::Buffer.new :int
}
}
puts "Benchmark [ :buffer_in ], :void performance (const String param), #{ITER}x calls"
+str = 'test'
10.times {
puts Benchmark.measure {
- ITER.times { LibTest.bench('test') }
+ ITER.times { LibTest.bench(str) }
}
}
puts "Benchmark [ :buffer_in ], :void performance (loop-allocated Buffer param), #{ITER}x calls"
diff --git a/bench/bench_buffer_alloc.rb b/bench/bench_buffer_alloc.rb
index 5c1ca1f..551209a 100644
--- a/bench/bench_buffer_alloc.rb
+++ b/bench/bench_buffer_alloc.rb
@@ -18,3 +18,10 @@ puts "Benchmark Buffer.new(4, 1, true)) performance, #{iter}x"
}
}
+puts "Benchmark Buffer.new(256, 1, true)) performance, #{iter}x"
+10.times {
+ puts Benchmark.measure {
+ iter.times { FFI::Buffer.new(256, 1, true) }
+ }
+}
+
diff --git a/bench/bench_closure_IrV.rb b/bench/bench_closure_IrV.rb
index 6b95c58..086d2df 100644
--- a/bench/bench_closure_IrV.rb
+++ b/bench/bench_closure_IrV.rb
@@ -28,7 +28,7 @@ puts "Benchmark [ ], :void closure block performance, #{ITER}x calls"
}
}
-puts "Benchmark [ ], :void pre-allocated closure performance, #{ITER}x calls"
+puts "Benchmark [ ], :void pre-allocated function performance, #{ITER}x calls"
10.times {
fn = FFI::Function.new(:void, [ :int ]) { |i| }
puts Benchmark.measure {
@@ -36,6 +36,14 @@ puts "Benchmark [ ], :void pre-allocated closure performance, #{ITER}x calls"
}
}
+puts "Benchmark [ ], :void pre-allocated callable performance, #{ITER}x calls"
+10.times {
+ fn = Proc.new { |i| }
+ puts Benchmark.measure {
+ ITER.times { LibTest.ffi_bench(fn, 2) }
+ }
+}
+
puts "Benchmark ruby method(1 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
diff --git a/bench/bench_enum.rb b/bench/bench_enum.rb
index 1758247..ec28922 100644
--- a/bench/bench_enum.rb
+++ b/bench/bench_enum.rb
@@ -4,7 +4,8 @@ module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
enum :foo, [ :a, :b, :c ]
- attach_function :ffi_bench, :bench_s32_v, [ :foo ], :void
+ attach_function :ffi_bench, :bench_s32_v, [ :foo ], :void, :save_errno => true
+ attach_function :ffi_bench_i, :bench_s32_v, [ :int ], :void, :save_errno => true
def self.rb_bench(i0); nil; end
end
@@ -14,6 +15,26 @@ puts "Benchmark [ enum ], :void performance, #{ITER}x calls"
ITER.times { LibTest.ffi_bench(:a) }
}
}
+
+puts "Benchmark [ enum ], :void with int arg performance, #{ITER}x calls"
+10.times {
+ puts Benchmark.measure {
+ ITER.times { LibTest.ffi_bench(1) }
+ }
+}
+
+puts "Benchmark [ :int ], :void performance, #{ITER}x calls"
+10.times {
+ puts Benchmark.measure {
+ ITER.times { LibTest.ffi_bench_i(1) }
+ }
+}
+puts "Benchmark [ :int ], :void with enum arg performance, #{ITER}x calls"
+10.times {
+ puts Benchmark.measure {
+ ITER.times { LibTest.ffi_bench_i(:a) }
+ }
+}
unless RUBY_PLATFORM == "java" && JRUBY_VERSION < "1.3.0"
require 'dl'
require 'dl/import'
diff --git a/bench/bench_memptr_alloc.rb b/bench/bench_memptr_alloc.rb
index f151a57..da05d64 100644
--- a/bench/bench_memptr_alloc.rb
+++ b/bench/bench_memptr_alloc.rb
@@ -16,4 +16,21 @@ puts "Benchmark MemoryPointer.new(4, 1, true)) performance, #{iter}x"
iter.times { FFI::MemoryPointer.new(4, 1, true) }
}
}
+[ 8, 16, 32, 64, 128, 256 ].each do |size|
+puts "Benchmark MemoryPointer.new(#{size}, 1, true)) performance, #{iter}x"
+10.times {
+ puts Benchmark.measure {
+ iter.times { FFI::MemoryPointer.new(size, 1, true) }
+ }
+}
+end
+
+if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
+ require 'java'
+ puts "calling java gc"
+ 10.times {
+ java.lang.System.gc
+ sleep 1
+ }
+end
diff --git a/bench/bench_strlen.rb b/bench/bench_strlen.rb
index 98d9753..424a8bf 100644
--- a/bench/bench_strlen.rb
+++ b/bench/bench_strlen.rb
@@ -1,5 +1,4 @@
require File.expand_path(File.join(File.dirname(__FILE__), "bench_helper"))
-str = "test"
module LibC
extend FFI::Library
ffi_lib 'c'
@@ -10,10 +9,18 @@ if LibC.strlen("test") != 4
raise ArgumentError, "FFI.strlen returned incorrect value"
end
+
puts "Benchmark FFI api strlen(3) performance, #{ITER}x"
+str = 'test' * 10
10.times {
puts Benchmark.measure {
ITER.times { LibC.strlen(str) }
}
}
+puts "Benchmark FFI api strlen(3), with new string performance, #{ITER}x"
+10.times {
+ puts Benchmark.measure {
+ ITER.times { LibC.strlen('test' * 10) }
+ }
+}