Skip to content

Instantly share code, notes, and snippets.

@copyninja
Created September 25, 2010 14:06
Show Gist options
  • Save copyninja/596863 to your computer and use it in GitHub Desktop.
Save copyninja/596863 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import ctypes
import timeit
def fact(n):
if n <= 1:
return 1
return n * fact(n-1)
if __name__ == "__main__":
t1 = timeit.Timer()
try:
a = fact(1000)
print "Python call %f" % t1.timeit()
except:
print "Python recursive call error stack depth exceeded"
pass
l = ctypes.CDLL('./test.so')
i = ctypes.c_int(1000)
t2 = timeit.Timer()
l._fact(i)
print "C call from python %f " % t2.timeit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment