@rasenove
oh sorry I should have introduced my self there, anyways, I'll do it again there =D
Thanks for the link you provided, but actually I didn't mention that I searched for optimization many times before, and I did came across this website and I've recently downloaded a book called "Optimizing software in C++" by Agner Fogb that helped me.
To make my question clear: for example there is a tip saying (I've seen this one during my search):
instead of doing this: x/2.0 do x*0.5 (multiplication is faster) ..
Classes are very nice to organize your code but it slows down you code.
I need this kind of tips. increasing the speed of my code with a fraction of a second will be something
I've learned c++ from cplusplus.com, youtube, and most of the time I just googled what I needed to know, I've got most of the answers/ideas from stackoverflow.
I'm really looking for tips that may look very basic (even silly) to any of you to say, but actually I don't have these tips.
@Factionwars
here is a snippet of a code I did some optimization for:
the loop is to update an array (line segments) with new segments after trimming the line.
From timing results I've found that making the three variables c1,c2,c3 increased the speed a bit since I only now caculate each one one time
bool c1,c2,c3;
for(iseg = 0 ; iseg < num ; iseg++)
{
min = _tmp_line[iter];iter++;
max = _tmp_line[iter];iter++;
if(!( pmin < min && pmax > max ))
{
c1 = pmin > min && pmin < max && pmax > max;
if(c1)
{
_line[iter2] = min;iter2++; //1st seg
_line[iter2] = pmin;iter2++;
}
c2 = pmax < max && pmax > min && pmin < min;
if(c2)
{
_line[iter2] = pmax;iter2++; //1st seg
_line[iter2] = max;iter2++;
}
c3 = pmin > min && pmax < max;
if( c3 && !c1 && !c2 ) //split
{
_line[iter2] = min;iter2++; //1st seg
_line[iter2] = pmin;iter2++;
_line[iter2] = pmax;iter2++; //2nd seg
_line[iter2] = max;iter2++;
}
if(!c1 && !c2 && !c3)
{
_line[iter2] = min;iter2++; //1st seg
_line[iter2] = max;iter2++; //1st seg
}
}
thanks for you replys guys !