Message80180
The multiprocessing module indeed has some overhead:
- the processes are spawned when needed. Before you perform performance
timings, you should "warm up" the Pool with a line like
pool.map(f, range(mul.cpu_count()))
(starting a process is a slowish operation specially on Windows)
This reduces timings by a factor of two.
- the dispatch overhead of multiprocessing is certainly greater than a
single multiplication. multiprocessing is for CPU-bound functions!
And do not forget that you have *tree* processes here: two from the
Pool, and your main program.
As Antoine said, try with this function instead:
def f(x):
for i in range(10):
x = x * x
return x
And the timings are much better... |
|
Date |
User |
Action |
Args |
2009-01-19 15:28:20 | amaury.forgeotdarc | set | recipients:
+ amaury.forgeotdarc, pitrou, jnoller, 0x666 |
2009-01-19 15:28:20 | amaury.forgeotdarc | set | messageid: <1232378900.04.0.630291269187.issue5000@psf.upfronthosting.co.za> |
2009-01-19 15:28:19 | amaury.forgeotdarc | link | issue5000 messages |
2009-01-19 15:28:19 | amaury.forgeotdarc | create | |
|