Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!husc6!uwvax!oddjob!tank!uxc!uxc.cso.uiuc.edu!uxg.cso.uiuc.edu!uxe.cso.uiuc.edu!mcdonald From: mcdonald@uxe.cso.uiuc.edu Newsgroups: comp.lang.c Subject: Re: Efficient programming - a maxim Message-ID: <225800080@uxe.cso.uiuc.edu> Date: 9 Oct 88 14:52:00 GMT References: <840@cernvax.UUCP> Lines: 25 Nf-ID: #R:cernvax.UUCP:840:uxe.cso.uiuc.edu:225800080:000:734 Nf-From: uxe.cso.uiuc.edu!mcdonald Oct 9 09:52:00 1988 >Some advice on efficient programming is: > Never do the same thing more than once >That implies using temporary variables to hold the results of operations for >later reuse. example: x = (a+b)*(c+d)-(c-d)/(a+b); versus t = a+b; x = t*(c+d)-(c-d)/t; I have checked this sort of thing, and larger examples, on many compilers, including vector machines, machines with poor optimizers, mediocre optimizers, and stupendous optimizers (VAX C). With a stupendous optimizer it of course doesn't matter one bit. With poor or mediocre optimizers, sometimes one is better, sometimes the other. You just have to try it. This is why hacks and tweaks have to come last, and are non-portable. Just like your momma taught you.