Skip to content

Instantly share code, notes, and snippets.

@qingfeng
Created October 2, 2009 14:40
Show Gist options
  • Select an option

  • Save qingfeng/199795 to your computer and use it in GitHub Desktop.

Select an option

Save qingfeng/199795 to your computer and use it in GitHub Desktop.
from multiprocessing import Pool,Process
def f(x):
return x*x
def f2(x):
return [i*i for i in x]
num = 10000000
'''
2.22 real 3.70 user 0.44 sys
'''
p1 = Process(target=f2, args=(xrange(num/2),))
p1.start()
p2 = Process(target=f2, args=(xrange(num/2,num),))
p2.start()
p1.join()
p2.join()
'''
8.40 real 12.86 user 1.97 sys
'''
# p = Pool(2)
# p.map(f,xrange(num))
'''
6.41 real 6.03 user 0.34 sys
'''
# map(f,xrange(num))
'''
5.66 real 5.17 user 0.45 sys
'''
# [i*i for i in xrange(num)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment