Re: Speedup Bitmap Parser

2009-02-17 Thread Peter Otten
Jayson Santos wrote: > On 17 fev, 14:00, bearophileh...@lycos.com wrote: >> Jayson Santos: >> >> > After changing my code to use only functions instead classes >> > my code is too much faster. >> > Here cProfile statistcs: >> > Using old code : 633608 function calls in 1.361 CPU seconds >> > Using

Re: Speedup Bitmap Parser

2009-02-17 Thread bearophileHUGS
Jayson Santos: > And here is the final code:http://pastebin.com/f3e20d669 Note that if you use Psyco this lookup trick isn't useful, but if the Psyco isn't available it can improve performance a little: append = BitmapList['lines'].append I suggest to replace this code: red, green, blue

Re: Speedup Bitmap Parser

2009-02-17 Thread Jayson Santos
On 17 fev, 14:00, bearophileh...@lycos.com wrote: > Jayson Santos: > > > After changing my code to use only functions instead classes > > my code is too much faster. > > Here cProfile statistcs: > > Using old code : 633608 function calls in 1.361 CPU seconds > > Using new code: 475487 function call

Re: Speedup Bitmap Parser

2009-02-17 Thread bearophileHUGS
Jayson Santos: > After changing my code to use only functions instead classes > my code is too much faster. > Here cProfile statistcs: > Using old code : 633608 function calls in 1.361 CPU seconds > Using new code: 475487 function calls in 0.800 CPU seconds If you show a pastebin of the new versio

Re: Speedup Bitmap Parser

2009-02-17 Thread Jayson Santos
On 16 fev, 21:47, bearophileh...@lycos.com wrote: > Jayson Santos: > > > Do I need use some patters or others progamming conventions ? > > That's a strong question... > Knowing OOP well is important, and it's often a good way to program, > etc. But... You may try to rewrite your code with functions

Re: Speedup Bitmap Parser

2009-02-17 Thread Tim Wintle
On Mon, 2009-02-16 at 16:47 -0800, bearophileh...@lycos.com wrote: > Jayson Santos: > > Do I need use some patters or others progamming conventions ? > > That's a strong question... > Knowing OOP well is important, and it's often a good way to program, > etc. But... You may try to rewrite your cod

Re: Speedup Bitmap Parser

2009-02-16 Thread bearophileHUGS
Jayson Santos: > Do I need use some patters or others progamming conventions ? That's a strong question... Knowing OOP well is important, and it's often a good way to program, etc. But... You may try to rewrite your code with functions only and no classes (well, you may need to use classes for the

Re: Speedup Bitmap Parser

2009-02-16 Thread Jayson Santos
On 16 fev, 20:41, bearophileh...@lycos.com wrote: > 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 goo

Re: Speedup Bitmap Parser

2009-02-16 Thread bearophileHUGS
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 y

Re: Speedup Bitmap Parser

2009-02-16 Thread Jayson Santos
On 16 fev, 18:29, bearophileh...@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)): >              

Re: Speedup Bitmap Parser

2009-02-16 Thread bearophileHUGS
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

Re: Speedup Bitmap Parser

2009-02-16 Thread Terry Reedy
Jayson Santos wrote: Hello people, I'm writing a Bitmap parser for study purposes, however when I parse a bitmap file and when I paint that file in a window, the script take to much time. 1. You turned constants into static methods called for every line, adding attribute lookup and function ca

Speedup Bitmap Parser

2009-02-16 Thread Jayson Santos
Hello people, I'm writing a Bitmap parser for study purposes, however when I parse a bitmap file and when I paint that file in a window, the script take to much time. How can I optimize my script loops to be faster ? Here is the script http://pastebin.com/m652b8d65 Best Regards Jayson Reis -- ht