Visual Studio somehow optimizes the below code to be 20 times faster (release with optimization vs. release with no optimization). What could it be doing?
for (unsigned n = 1; n != units.size(); n++)
for (unsigned j = 0; j != (units.size() - n); j++)
{
unsigned sizesMap[11] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
for (auto it = units.begin() + n; it != (units.begin() + (n + j + 1)); it++)
{
for (unsigned k = 1; k != 11; k++)
{
sizesMap[k] += (*it).sizes[k];
}
}
//do something with sizesmap
}
Unit class has a sizes array (10 members). The first two loops give all the possible sequences of "unit" in the vector. (1-2, 1-3, 1-100, 2-3, 2-4, 2-100, etc), which I then compare with one another using the sizesmap. I tried unrolling the inner loop and just adding sizesmap 10 times, that gave about 2% performance improvement. I compiled with Visual Studio 2013. Could it be vectorization (adds the (*it).sizes to sizesmap in one go)? Or are the loops ineffective somehow?
sizesMap[0]
is untouched in the inner loop? – ratchet freak Jan 13 '14 at 14:04units
variable, orUnit
class. – ChrisW Jan 13 '14 at 18:07sizesMap
, do you modify the entries ofsizesMap
or not? – 200_success♦ Jan 13 '14 at 19:11