Skip to content

Instantly share code, notes, and snippets.

@a2chub
Created May 3, 2011 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a2chub/953836 to your computer and use it in GitHub Desktop.
Save a2chub/953836 to your computer and use it in GitHub Desktop.
import time
import sys
from multiprocessing import Process
def fibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
def doInThread(i):
start = time.time()
for x in range(50):
result = fibonacci(x)
print result
end = time.time()
print "%d time %d sec"%(i, end -start)
if __name__ == "__main__":
count = 1
if len(sys.argv) > 1:
count = int(sys.argv[1])
for i in range(0, count):
Process(target = doInThread, args = (i, )).start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment