Created
May 3, 2011 17:55
-
-
Save a2chub/953836 to your computer and use it in GitHub Desktop.
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
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