Duncan Booth duncan at NOSPAMrcp.co.uk
Wed Sep 11 04:32:54 EDT 2002

Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote in 
news:Xns92865CE1C916Aduncanrcpcouk at
> The code below gives these timings on my machine:
> 3.84s: 1000000 x New()
> 3.89s: 1000000 x New2()
> 2.39s: 1000000 x Old()
> 5.19s: 10000 x attributes(<class '__main__.New'>)
> 5.81s: 10000 x attributes(<class '__main__.New2'>)
> 4.17s: 10000 x attributes(__main__.Old)

Sorry about the bad form of following up to my own post, but I thought I 
had better add that the above timings are on Python 2.2.1 and I forgot to 
specify -O.

The optimised times for 2.2.1 are:
3.77s: 1000000 x New()
3.81s: 1000000 x New2()
2.33s: 1000000 x Old()
4.94s: 10000 x attributes(<class '__main__.New'>)
5.56s: 10000 x attributes(<class '__main__.New2'>)
3.92s: 10000 x attributes(__main__.Old)

 Using the latest CVS build I get rather different timings:

0.94s: 1000000 x New()
1.05s: 1000000 x New2()
1.39s: 1000000 x Old()
3.52s: 10000 x attributes(<class '__main__.New'>)
4.36s: 10000 x attributes(<class '__main__.New2'>)
3.05s: 10000 x attributes(__main__.Old)

So it appears that creating object-derived classes is now faster than 
creating old-style classes, although both tests are much faster than in 
2.2. Setting attributes is still somewhat slower. Oh, and the -O flag on 
the CVS build has no measurable effect.

Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list