Dan Byström’s Bwain

Blog without an interesting name

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

4 Responses to “Optimizing away”

  1. 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

  2. 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)

  3. […] Comments (RSS) « Optimizing away […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: