Skip to content

Instantly share code, notes, and snippets.

@tka
Last active August 29, 2015 14:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tka/bab2e516f125511de67e to your computer and use it in GitHub Desktop.
Save tka/bab2e516f125511de67e to your computer and use it in GitHub Desktop.
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
Copy link

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