Last active
August 29, 2015 14:24
-
-
Save tka/bab2e516f125511de67e to your computer and use it in GitHub Desktop.
golang 1.5 shared library + ruby ffi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 搭配 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user system total real | |
1.130000 0.000000 1.130000 ( 1.132376) | |
0.060000 0.000000 0.060000 ( 0.068342) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.