Optimizing away
Posted by Dan Byström on December 16, 2008
Follow-up on Improving performance… and Genetic Programming: Evolution of Mona Lisa.
I just tested that I can optimize this loop:
unchecked { unsafe { fixed ( Pixel* psourcePixels = sourcePixels ) { Pixel* p1 = (Pixel*)bd.Scan0.ToPointer(); Pixel* p2 = psourcePixels; for ( int i = sourcePixels.Length ; i > 0 ; i--, p1++, p2++ ) { int r = p1->R - p2->R; int g = p1->G - p2->G; int b = p1->B - p2->B; error += r * r + g * g + b * b; } } } }
so that it runs even 60% faster. Don’t dare to tell you how, however.
EDIT: Continued here Ekeforshus
biofractal said
I am in awe of your brilliant optimisation work so far so please do not deny the world the extra 60%. I need the speed man 🙂 Please post your code. Thanks.
IMO, your work is more interesting than the original evolisa. That was a great demo, it really hit the mark, but it used (almost accidentally) some pretty old-fashioned evolutionary logic (called ‘single objective’) but there is plenty of modern EA research out there that uses much more powerful algorithms (multi-objective).
If you have an interest check this out: http://www.tik.ee.ethz.ch/sop/publicationListFiles/zlt2001a.pdf
imma said
well if we have to guess, i’d say you don’t bother to distinguish pixels/colors & just loop through the colour bytes?
also would a check for equality be better: i!=0 or even set up a test pointer to compare p1/p2 to
(wow i need to get round to settings stuff up on my computer)
danbystrom said
https://danbystrom.se/2008/12/22/optimizing-away-ii/
Optimizing away II « Dan Byström’s Bwain said
[…] Comments (RSS) « Optimizing away […]