code speed

Started by
11 comments, last by edwinnie 20 years, 3 months ago
ok thx fer all the replies!
Advertisement
quote:Original post by Charles B

I think it''s a common and false argument. If every piece of your code is written twice slower than what should be, even if you optimize a few bottlenecks (let them cost 30% of the ressources) the rest will still slow down the whole soft by a huge factor. So it''s important to know and include some basic rules of optimizations in a coding style.


It''s common but not false. Yes, there are cases where you learn to avoid certain constructs and make extensive use of others, but for most of the application it really does not matter.

And anyone who waits until the app is finished to profile is not properly doing their job. Ideally, each subsytem would be profiled in seclusion from the rest of the poject before it is integrated, then profiling should be performed to see how it affects the project as a whole. This is not always possible during the various stages of development but is a good practive to try and follow.

In the example he presented, my first guess is that option 2 is fastest. However, I have no way of knowing that for sure without either seeing the compiler output or profiling. Who knows? One compiler might optimize away the loop in the first case so that the resultant output is the same, while another may not. In the end, if this is a commonly used function which is used in critical places, the only way to be sure is to plug it in and profile.
quote:*p1++=*p2++ + *p3++ style means more register pressure, more instructions, more code cache lines, more AGIs than a
p1 = p2 + p3 style.<hr height=1 noshade></SPAN></BLOCKQUOTE><br>Ah, but that wasn''t &#111;ne of the options.<br><br>The second example was explicitly unrolled. I will agree with you about p1 (etc.) – I''d let the optimizer perform the strength reduction for me, rather than stating it explicitly – but working within the constraints of the system, the first, strength-reduced iteration is better than the hardcoded unrolled loop.<br>
char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;}  /*** drpizza@battleaxe.net ***/

This topic is closed to new replies.

Advertisement