Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!rutgers!uwvax!mcvoy From: mcvoy@uwvax.UUCP Newsgroups: comp.sys.m68k Subject: Re: Incidentally ... (was Re: Recent Motorola ad) Message-ID: <3425@rsch.WISC.EDU> Date: Sat, 4-Apr-87 18:14:13 EST Article-I.D.: rsch.3425 Posted: Sat Apr 4 18:14:13 1987 Date-Received: Sun, 5-Apr-87 13:19:46 EST References: <362@sbcs.UUCP> <1466@ncr-sd.SanDiego.NCR.COM> <580@plx.UUCP> <73@eps2.UUCP> <6134@mimsy.UUCP> Reply-To: mcvoy@rsch.WISC.EDU (Larry McVoy) Distribution: comp Organization: U of Wisconsin CS Dept Lines: 41 (Chris Torek) writes: >> while (wy--) { >> j = wx; >> while (j--) { > >(The above is an inner loop.) Such loops should usually (always?) >be written as > > while (--j >= 0) > >---assuming j is signed. Why? They both do the same thing, but > [good justification that (--j >= 0) is faster] I'm not sure that it worth everyones time to be thinking about this. And I speak from a certain amount of experience, to wit: last semester I had to write a fake TCP/IP from scratch and I wanted to make a fast implementation. Over the course of the semester I gathered a directory full of t.{c,s} files where I was looking at exactly this sort of thing. I really wanted fast code. As it turned out, my implementation did not gain much at all from all this extra work - mainly because it as just not used. The old "90% of the time 10% of the code" saw applies. I would have been much better off to profile my code and rewrite the bottlenecks. Please don't take this the wrong way - Chris is a smart guy, and he's right in a technical sense. And I get a warm fuzzy feeling from writing my code in a efficient manner too. It's just that I think it's misleading to to appear worried about this sort of thing in general sense - it really belongs in the "profiling code" section, not "general programming tips". Kernighan and Plauger say "Premature Optimization is the root of all evil". I think this is a bit extreme, but I agree in principle. Food for thought (?), --larry -- Larry McVoy mcvoy@rsch.wisc.edu or uwvax!mcvoy "It's a joke, son! I say, I say, a Joke!!" --Foghorn Leghorn