Speedup Bitmap Parser

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Feb 16 18:41:37 EST 2009

Jayson Santos:
> Here is the new code using your changeshttp://pastebin.com/m6dfe619d
> And here is the profilerhttp://pastebin.com/m74d282b8

I have suggested you to profile the program mostly for pedagogical
purposes, it's often a good thing to do if you want to speed up a
program. But now it's your job to read the output of the profiler and
try to find where the performance problems are. The profiler output
will be simpler for you to read if you sort lines according to
something better than method name (something like the time used by
functions sounds better) and you tell the profiler to show only the
first few lines.

But a profiler isn't enough, you also need to use the brain. Your code
looks a bit too much OOP :-) So in Java your code may run fast enough,
but in Python it may be too much slow.
The suggestions by Terry are good if you want to speed up your code
signifiantly. Creating a very large amount of objects inside inner
loops a slow thing in Java too, not just in Python. Generally to
create an object you need to allocate memory. Try to write your program
(s) avoiding all or most memory allocations inside the inner loops,
and you will see a big improvement in running speed.


More information about the Python-list mailing list