I don't know what number to brew, but I use a package written in Golang from Python (multilingual)
Python : 2.7 Golang : 1.7 OS : CentOS release 6.8 Memory : 2048MB CPU : 3core
PythonLibrary ctypes
fib.go
package main
import "C"
//export fib
func fib(n uint) uint {
if n <= 1 {
return n
}
return fib(n-1) + fib(n-2)
}
func main() {}
build
go build -o fib.so -buildmode=c-shared fib.go
fib_go.py
from ctypes import *
lib = cdll.LoadLibrary("./fib.so")
## arg
lib.fib.argtypes = [c_longlong]
## return
lib.fib.restype = c_longlong
print "fib %d" % lib.fib(40)
fib.py
#!/usr/bin/env python
def fib(n):
if n <= 1:
return n
else:
return fib(n-1) + fib(n-2)
print(fib(40))
fib_go.py
#time python fib_go.py
fib 102334155
real 0m1.171s
user 0m1.105s
sys 0m0.071s
fib.py
#time python fib_go.py
102334155
real 0m46.598s
user 0m46.449s
sys 0m0.030s
Recommended Posts