Skip to content

Instantly share code, notes, and snippets.

@tka tka/benchmark.rb
Last active Aug 29, 2015

Embed
What would you like to do?
golang 1.5 shared library + ruby ffi
# 搭配 http://qiita.com/yanolab/items/1e0dd7fd27f19f697285 服用
require 'ffi'
require 'benchmark'
module LibGo
extend FFI::Library
ffi_lib './libgo.so'
attach_function :fib, [:int], :int
end
def fib(i)
return i if i < 2
return fib(i-2)+fib(i-1)
end
n=10000
Benchmark.bm do |x|
x.report{ n.times{ fib(16); }}
x.report{ n.times{ LibGo.fib(16) }}
end
user system total real
1.130000 0.000000 1.130000 ( 1.132376)
0.060000 0.000000 0.060000 ( 0.068342)
@benjaminpelc

This comment has been minimized.

Copy link

benjaminpelc commented Aug 19, 2015

Hi, I have been trying to find out how do exactly this, how did you create libgo.so? Can't seem to find anywhere how to make the .so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.