[Tutor] script too slow
Michael Janssen
Janssen@rz.uni-frankfurt.de
Mon Feb 24 05:08:01 2003
On Sun, 23 Feb 2003, Paul Tremblay wrote:
> In addition, I wonder if I should use lists in some way. For example, I
> could create one giant list.
>
> allowed = ['\par', '\pard', etc]
dictionary lookups are faster in python: use dictionaries for lookups and
lists for sorting. These ways both the datastructures are optimized.
Therefore it's realy amazing, what you are experiencing with your code :-(
Fred suggestion about a super dictionary seems valueable.
Have you already "profiled" your code?
# in script:
import profile
profile.run('<function to profile: func(arg)>', '<file to write to>')
# then in interpreter:
import pstats
p = pstats.Stats('<file written to>')
p.print_stats()
# nicer output
p.strip_dirs().sort_stats('time').print_stats()
This possibly gives you a hint what kind of operations takes the time.
Michael