[Pyobjc-dev] Re: [Python-Dev] PyBuffer* vs. array.array()
Brought to you by:
ronaldoussoren
From: Christian T. <ti...@ti...> - 2003-01-05 23:25:33
|
Guido van Rossum wrote: >>>I'm not sure if you were joking, but why not write >>> >>> singlePlane.fromlist([0] * (width*height*3)) >> >> Or cheaper and faster for large width and height: >> >> singlePlane = array.array('B', [0])*width*height*3 > > > Correct; then even better: > > singlePlane = array.array('B', [0]) * (width*height*3) > > i.e. do only one sequence repeat rather than three. For "large" widths and heights, like 1000*1000, this effect is remarkably small: About 3 percent only. The above is true for simple lists. There are also counterexamples, where you are extremely wrong (sorry), most probably due to the mplementation, but also by the effect, that medium sized flat objects can be copied more efficiently than very small ones. >>> if 1: ... t = time.clock() ... for i in xrange(100): ... s = ' ' * 1000 * 1000 ... print time.clock()-t ... 0.674784644417 >>> if 1: ... t = time.clock() ... for i in xrange(100): ... s = ' ' * 1000000 ... print time.clock()-t ... 6.28695295072 >>> Did I hear you head knocking on the keyborard? ciao - chris -- Christian Tismer :^) <mailto:ti...@ti...> Mission Impossible 5oftware : Have a break! Take a ride on Python's Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/ 14109 Berlin : PGP key -> http://wwwkeys.pgp.net/ work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776 PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04 whom do you want to sponsor today? http://www.stackless.com/ |