Fastest Way To Loop Through Every Pixel

H J van Rooyen mail at microcorp.co.za
Fri Jul 28 08:49:58 EDT 2006


 "Paul McGuire" <ptmcg at austin.rr._bogus_.com> wrote:

| "H J van Rooyen" <mail at microcorp.co.za> wrote in message
| news:mailman.8646.1154071426.27775.python-list at python.org...
| > "Paul McGuire" <ptmcg at austin.rr._bogus_.com> wrote:
| >
| > | Even downer-and-dirtier, you could approximate 30 with 32, 59 with 64,
| and
| > | 11 with 8, and do bit-shifting instead of multiplying:
| > |
| > | def darkness(img,x,y):
| > |     return  (RedVal(img,x,y) << 5) + (GreenVal(img,x,y) << 6) +
| > | (BlueVal(img,x,y) << 3)
| > |
| > |
| > | -- Paul
| >
| > *grin* - a man after my own heart! - how do you multiply by ten? - shift,
| save a
| > copy, shift twice more and add the copy...
| >
| > - Hendrik
| >
| Sadly, my timeit results show this saves only a little time, and
| shift-copy-shiftsomemore-and-add is even slower then just doing the original
| floating point multiply.  The biggest win is in prelookup of Image.GetXXX
| functions.
|
| -- Paul

I was not seriously suggesting this for use in python on a pc - its the sort of
rubbish you do on a small embedded machine that has a reduced instruction set
and no multiplier...

- Hendrik






More information about the Python-list mailing list