can multi-core improve single funciton?
clp2 at rebertia.com
Tue Feb 10 07:43:50 CET 2009
On Mon, Feb 9, 2009 at 10:28 PM, oyster <lepto.python at gmail.com> wrote:
> I mean this
> def fib(n):
> if n<=1:
> return 1
> return fib(n-1)+fib(n-2)
> timeit(fib(500)) #this show 20 seconds
> timeit(fib(500)) #this show 10 seconds
> Is it possible?
> and more, can threads/multi-processors/clusters be used to improve fib?
Considering the GIL, I highly doubt it so. Also, the algorithm is
fundamentally linear -- each result depends on previous results -- so
I don't think you can easily parallelize it (if at all). You'd
probably get greater speedup using memoization.
Follow the path of the Iguana...
More information about the Python-list