Skip to content

Commit

Permalink
Namespace all benchmarks since they are loaded into one process
Browse files Browse the repository at this point in the history
This is a follow-up to the previous commit.
The benchmarks also made use of the redefinition feature of struct layouts.
Namespacing avoids redefinition, but uses separate classes for all structs.
  • Loading branch information
larskanis committed Jan 8, 2020
1 parent 0be72ee commit 18cb2cf
Show file tree
Hide file tree
Showing 36 changed files with 1,314 additions and 1,250 deletions.
36 changes: 19 additions & 17 deletions bench/bench_FFFrV.rb
@@ -1,24 +1,26 @@
require_relative 'bench_helper'

module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_f32f32f32_v, [ :float, :float, :float ], :void
def self.rb_bench(a0, a1, a2); nil; end
end
module BenchFFFrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_f32f32f32_v, [ :float, :float, :float ], :void
def self.rb_bench(a0, a1, a2); nil; end
end


puts "Benchmark [ :float, :float, :float ], :void performance, #{ITER}x calls"
f = 1.0
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench_f32f32f32_v(f, f, f) }
puts "Benchmark [ :float, :float, :float ], :void performance, #{ITER}x calls"
f = 1.0
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench_f32f32f32_v(f, f, f) }
}
}
}

puts "Benchmark ruby method(1 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
ITER.times { LibTest.rb_bench(f, f, f) }
puts "Benchmark ruby method(1 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
ITER.times { LibTest.rb_bench(f, f, f) }
}
}
}
end
60 changes: 31 additions & 29 deletions bench/bench_FrV.rb
@@ -1,36 +1,38 @@
require_relative 'bench_helper'

module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_f32_v, [ :float ], :void
def self.rb_bench(i0); nil; end
end
module BenchFrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_f32_v, [ :float ], :void
def self.rb_bench(i0); nil; end
end


puts "Benchmark [ :float ], :void performance, #{ITER}x calls"
f = 1.0
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.bench_f32_v(f)
LibTest.bench_f32_v(f)
LibTest.bench_f32_v(f)
LibTest.bench_f32_v(f)
i += 4
end
puts "Benchmark [ :float ], :void performance, #{ITER}x calls"
f = 1.0
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.bench_f32_v(f)
LibTest.bench_f32_v(f)
LibTest.bench_f32_v(f)
LibTest.bench_f32_v(f)
i += 4
end
}
}
}

puts "Benchmark ruby method(1 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.rb_bench(f)
LibTest.rb_bench(f)
LibTest.rb_bench(f)
LibTest.rb_bench(f)
i += 4
end
puts "Benchmark ruby method(1 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.rb_bench(f)
LibTest.rb_bench(f)
LibTest.rb_bench(f)
LibTest.rb_bench(f)
i += 4
end
}
}
}
end
47 changes: 24 additions & 23 deletions bench/bench_IIIIIIrV.rb
@@ -1,29 +1,30 @@
require_relative 'bench_helper'

module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, 'bench_s32s32s32s32s32s32_v', [ :int, :int, :int, :int, :int, :int ], :void, :save_errno => false
def self.rb_bench(i0, i1, i2, i3, i4, i5); nil; end
end
module BenchIIIIIIrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, 'bench_s32s32s32s32s32s32_v', [ :int, :int, :int, :int, :int, :int ], :void, :save_errno => false
def self.rb_bench(i0, i1, i2, i3, i4, i5); nil; end
end

puts "Benchmark [ :int, :int, :int, :int, :int, :int ], :void performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.ffi_bench(1, 2, 3, 4, 5, 6)
i += 1
end
puts "Benchmark [ :int, :int, :int, :int, :int, :int ], :void performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.ffi_bench(1, 2, 3, 4, 5, 6)
i += 1
end
}
}
}

puts "Benchmark ruby method(6 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.rb_bench(0, 1, 2, 3, 4, 5)
i += 1
end
puts "Benchmark ruby method(6 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.rb_bench(0, 1, 2, 3, 4, 5)
i += 1
end
}
}
}

end
22 changes: 12 additions & 10 deletions bench/bench_IIIrI.rb
@@ -1,15 +1,17 @@
require_relative 'bench_helper'

module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench, :bench_s32s32s32_v, [ :int, :int, :int ], :int
end
module BenchIIIrI
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench, :bench_s32s32s32_v, [ :int, :int, :int ], :int
end


puts "Benchmark [ :int, :int, :int ], :int performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench(0, 1, 2) }
puts "Benchmark [ :int, :int, :int ], :int performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
ITER.times { LibTest.bench(0, 1, 2) }
}
}
}
end
46 changes: 24 additions & 22 deletions bench/bench_IIIrV.rb
@@ -1,28 +1,30 @@
require_relative 'bench_helper'

module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, :bench_s32s32s32_v, [ :int, :int, :int ], :void, :save_errno => false
def self.rb_bench(i0, i1, i2); nil; end
end
module BenchIIIrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, :bench_s32s32s32_v, [ :int, :int, :int ], :void, :save_errno => false
def self.rb_bench(i0, i1, i2); nil; end
end

puts "Benchmark [ :int, :int, :int ], :void performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.ffi_bench(0, 1, 2)
i += 1
end
puts "Benchmark [ :int, :int, :int ], :void performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.ffi_bench(0, 1, 2)
i += 1
end
}
}
}

puts "Benchmark ruby method(3 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.rb_bench(0, 1, 2)
i += 1
end
puts "Benchmark ruby method(3 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.rb_bench(0, 1, 2)
i += 1
end
}
}
}
end
58 changes: 30 additions & 28 deletions bench/bench_IrV.rb
@@ -1,34 +1,36 @@
require_relative 'bench_helper'

module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, :bench_s32_v, [ :int ], :void, :save_errno => false
def self.rb_bench(i0); nil; end
end
module BenchIrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :ffi_bench, :bench_s32_v, [ :int ], :void, :save_errno => false
def self.rb_bench(i0); nil; end
end

puts "Benchmark [ :int ], :void performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.ffi_bench(0)
LibTest.ffi_bench(0)
LibTest.ffi_bench(0)
LibTest.ffi_bench(0)
i += 4
end
puts "Benchmark [ :int ], :void performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.ffi_bench(0)
LibTest.ffi_bench(0)
LibTest.ffi_bench(0)
LibTest.ffi_bench(0)
i += 4
end
}
}
}

puts "Benchmark ruby method(1 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.rb_bench(0)
LibTest.rb_bench(0)
LibTest.rb_bench(0)
LibTest.rb_bench(0)
i += 4
end
puts "Benchmark ruby method(1 arg) performance, #{ITER}x calls"
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.rb_bench(0)
LibTest.rb_bench(0)
LibTest.rb_bench(0)
LibTest.rb_bench(0)
i += 4
end
}
}
}
end
29 changes: 15 additions & 14 deletions bench/bench_LLLrV.rb
@@ -1,20 +1,21 @@
require_relative 'bench_helper'

module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_s64s64s64_v, [ :long_long, :long_long, :long_long ], :void, :save_errno => false
end
module BenchLLLrV
module LibTest
extend FFI::Library
ffi_lib LIBTEST_PATH
attach_function :bench_s64s64s64_v, [ :long_long, :long_long, :long_long ], :void, :save_errno => false
end


puts "Benchmark [ :long_long, :long_long, :long_long ], :void performance, #{ITER}x calls"
puts "Benchmark [ :long_long, :long_long, :long_long ], :void performance, #{ITER}x calls"

10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.bench_s64s64s64_v(0, 1, 2)
i += 1
end
10.times {
puts Benchmark.measure {
i = 0; while i < ITER
LibTest.bench_s64s64s64_v(0, 1, 2)
i += 1
end
}
}
}

end

0 comments on commit 18cb2cf

Please sign in to comment.