Python in game development?

Daniel Berlin dan at cgsoftware.com
Wed Aug 30 02:27:57 EDT 2000


> It took me two minutes to optimize your Python code by more than a
> factor of 500 (Python 1.5.2 on a PentiumPro 200 running Linux 2.0.29,
> libc5):
> 
> def recfib (n, cache = {}) :
>     if not cache.has_key (n) :
>         if n <= 2:
>             cache [n] = 1
>         else:
>             cache [n] = recfib (n-1) + recfib (n-2)
>     return cache [n]
> 
> print recfib(33)
> 
> The timing of the optimized version is quite volatile -- I get results
> between 0m0.055s and 0m0.167s, while your version consistently uses
> more than 50 seconds.
> 
> Now that optimization is obvious. My point is that Python favors
> optimization much more than some of the other languages you
> benchmarked (C the most obvious case, I don't know about Forth).

The part i love is where I make a 1 line modification to your optimized
version (1 to 1.0) so we use floats, and change python to use
recfib(1476), and we still get the same fast results. 
(1476 is the best you can do without it just saying "inf").

 > 
> Don't-trust-benchmarks, ly
> Christian
> 
> 





More information about the Python-list mailing list