Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 79 lines (66 sloc) 1.799 kB
f0ed552 Add simple callback benchmark
Wayne Meissner authored
1 require File.expand_path(File.join(File.dirname(__FILE__), "bench_helper"))
2
3 module LibTest
4 extend FFI::Library
5 ffi_lib LIBTEST_PATH
305f0d6 Fix up signature
Wayne Meissner authored
6 callback :closureVrV, [ ], :void
2513929 Add non-ruby-thread callback benchmarks
Wayne Meissner authored
7
f0ed552 Add simple callback benchmark
Wayne Meissner authored
8 attach_function :ffi_bench, :testClosureVrV, [ :closureVrV ], :void
30e7a9b Tag the non-ruby thread trampoline method as @blocking = true so it w…
Wayne Meissner authored
9 @blocking = true
2513929 Add non-ruby-thread callback benchmarks
Wayne Meissner authored
10 attach_function :threaded_bench, :testThreadedClosureVrV, [ :closureVrV, :int ], :void
11
12 def self.rb_bench(&block)
13 yield
14 end
f0ed552 Add simple callback benchmark
Wayne Meissner authored
15 end
2513929 Add non-ruby-thread callback benchmarks
Wayne Meissner authored
16
f0ed552 Add simple callback benchmark
Wayne Meissner authored
17 unless RUBY_PLATFORM == "java" && JRUBY_VERSION < "1.3.0"
18 require 'dl'
19 require 'dl/import'
20 module LibTest
21 if RUBY_VERSION >= "1.9.0"
22 extend DL::Importer
23 else
24 extend DL::Importable
25 end
26 dlload LIBTEST_PATH
27 extern "int returnInt()"
28 end
29 end
30
7ef697d Actually yield to the closure in the pure-ruby version, and add a pre…
Wayne Meissner authored
31 puts "Benchmark [ ], :void closure block performance, #{ITER}x calls"
f0ed552 Add simple callback benchmark
Wayne Meissner authored
32 10.times {
33 puts Benchmark.measure {
34 ITER.times { LibTest.ffi_bench { } }
35 }
36 }
37
7ef697d Actually yield to the closure in the pure-ruby version, and add a pre…
Wayne Meissner authored
38 puts "Benchmark [ ], :void pre-allocated function pointer performance, #{ITER}x calls"
39 10.times {
40 fn = FFI::Function.new(:void, []) {}
41 puts Benchmark.measure {
42 ITER.times { LibTest.ffi_bench fn }
43 }
44 }
45
46 puts "Benchmark [ ], :void pre-allocated closure performance, #{ITER}x calls"
47 10.times {
48 proc = lambda {}
49 puts Benchmark.measure {
50 ITER.times { LibTest.ffi_bench proc }
51 }
52 }
f0ed552 Add simple callback benchmark
Wayne Meissner authored
53
2513929 Add non-ruby-thread callback benchmarks
Wayne Meissner authored
54 puts "Benchmark [ ], :void non-ruby thread closure performance, #{ITER}x calls"
55 10.times {
56 fn = FFI::Function.new(:void, []) {}
57 puts Benchmark.measure {
58 LibTest.threaded_bench(fn, ITER)
59 }
60 }
61
62
f0ed552 Add simple callback benchmark
Wayne Meissner authored
63 #unless RUBY_PLATFORM == "java" && JRUBY_VERSION < "1.3.0"
64 #puts "Benchmark DL void bench() performance, #{ITER}x calls"
65 #10.times {
66 # puts Benchmark.measure {
67 # ITER.times { LibTest.returnInt }
68 # }
69 #}
70 #end
71
72 puts "Benchmark ruby method(no arg) performance, #{ITER}x calls"
73 10.times {
74 puts Benchmark.measure {
75 ITER.times { LibTest.rb_bench {} }
76 }
77 }
78
Something went wrong with that request. Please try again.