Speedup Bitmap Parser
Jayson Santos
santosdosreis at gmail.com
Mon Feb 16 18:08:58 EST 2009
On 16 fev, 18:29, bearophileH... at lycos.com wrote:
> Jayson Santos:
>
> > Hello people, I'm writing a Bitmap parser for study purposes,
>
> This code:
>
> x = 0
> y = 0
> for line in bmp.bitmap_lines.lines:
> for color in xrange(len(line.colors)):
> canvas.create_line(x, y, x+1, y, fill="#%02x%02x%02x"
> % (line.colors[color].red, line.colors[color].green, line.colors
> [color].blue))
> x += 1
> x = 0
> y += 1
>
> May be replaced with something like:
>
> for x, color in enumerate(line.colors):
> canvas.create_line(x, y, x+1, y, fill="#%02x%02x%02x" %
> (color.red, color.green, color.blue))
>
> And maybe a RGBTriple may be replaced with an immutable namedtuple.
> Using nested classes may be overkill for this program.
>
> Use the Python profiler and profile your code with a real image, and
> show us/me the profiler results, so I can give you some suggestions to
> speed up your code.
>
> Bye,
> bearophile
Hello bearophile,
Thank you and Terry for your answers.
Here is the new code using your changes http://pastebin.com/m6dfe619d
And here is the profiler http://pastebin.com/m74d282b8
Best Regards
Jayson Reis
More information about the Python-list
mailing list