I could use some help making this Python code run faster usingonly Python code.
Delaney, Timothy (Tim)
tdelaney at avaya.com
Mon Sep 24 07:19:41 CEST 2007
Python Maniac wrote:
> Some benchmarks showing the effectiveness of using Psyco:
> scramble: 4.210
> scramble_listcomp: 2.343
> scramble_gencomp: 2.599
> scramble_map: 1.960
> scramble_imap: 2.231
> scramble_dict: 2.387
> scramble_dict_map: 0.535
> scramble_dict_imap: 0.726
> scramble_translate: 0.010
> Now with Psyco...
> scramble: 0.121 4.088 34.670x faster
> scramble_listcomp: 0.215 2.128 10.919x faster
> scramble_gencomp: 2.563 0.036 1.014x faster
> scramble_map: 2.002 -0.043 0.979x slower
> scramble_imap: 2.175 0.056 1.026x faster
> scramble_dict: 0.199 2.188 11.983x faster
> scramble_dict_map: 0.505 0.029 1.058x faster
> scramble_dict_imap: 0.728 -0.001 0.998x slower
> scramble_translate: 0.009 0.001 1.111x faster
> Overall, Psyco helped my little process of converting 20 MB worth of
> ASCII into what may not look like the original at 6x faster than
> without Psyco.
One thing you should notice with the above results:
Psyco made your initial, totally unoptimised algorithm the fastest of
all (except for translate, which is in a different league of course -
but is much more limited in what it can do).
The other algorithms are already heavily working in C code (dicts, etc),
but the initial algorithm provided lots of opportunities for Psyco to
hook in and use the runtime behaviour.
So, before trying to optimise, see if Psyco gives you the performance
More information about the Python-list