Optimizations - Programmer vs. Compiler? is an 'Ask Slashdot' article. I've always been interested in program optimization ever since I found out that on my Color Computer II assigning a variable the value of '.' was faster than assigning it the value of '0'. This thread on Slashdot is all over my head but has interesting pearls such as:
for(x=0; x < width; x++)
{
for(y=0; y < height; y++)
{
...
}
}
versus
for(y=0; y < height; y++)
{
for(x=0; x < width; x++)
{
...
}
}
Note that the first bit of code will likely run faster, read more to see why....
The reasoning is that if you access the data in order of rows you will likely be holding a portion of the row in cache wheras if you go by column you will likely be overwriting the cache. Pretty nifty. But I don't know how you test for this other than actually making a test program and running it. I am sure compiler gurus can just tell what is going on depending on the compiler but this is all way out of my league. I just like to read stuff like this and then comment on it so I seem smarter than I really am.
I still don’t understand. That’s why I mount tapes for a living.
I see dumb people... - Friday 04 March '05 - 16:13