Skip to content

Instantly share code, notes, and snippets.

@bonfy
Last active December 5, 2016 23:12
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 bonfy/1c6ba24eb226206275255efbc6ce0845 to your computer and use it in GitHub Desktop.
Save bonfy/1c6ba24eb226206275255efbc6ce0845 to your computer and use it in GitHub Desktop.
import time
import multiprocessing
def timerecord(func):
def wrapper(*args, **kwargs):
start = time.time()
func(*args, **kwargs)
end = time.time()
print 'COST: {}'.format(end - start)
return wrapper
def fib(n):
if n<= 2:
return 1
return fib(n-1) + fib(n-2)
@timerecord
def nomultiprocess():
fib(20)
fib(20)
@timerecord
def hasmultiprocess():
jobs = []
for i in range(2):
p = multiprocessing.Process(target=fib, args=(20,))
p.start()
jobs.append(p)
for p in jobs:
p.join()
if __name__ == '__main__':
nomultiprocess()
hasmultiprocess()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment