-
-
Save qingfeng/199795 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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