Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site umcp-cs.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.lang.c Subject: Re: more questions about efficient C code Message-ID: <496@umcp-cs.UUCP> Date: Thu, 27-Jun-85 03:38:58 EDT Article-I.D.: umcp-cs.496 Posted: Thu Jun 27 03:38:58 1985 Date-Received: Sat, 29-Jun-85 00:14:38 EDT References: <474@crystal.UUCP> <397@umcp-cs.UUCP> <721@wlcrjs.UUCP> Distribution: net Organization: U of Maryland, Computer Science Dept., College Park, MD Lines: 32 > This example [ if ((fp = fopen(...)) == NULL) vs fp = fopen(...); if (fp == NULL) ] > bothers me. I'm not sure what all makes up the fopen subroutine, > but the addition or subtraction of one measly assignment statement > *has* to be negligible when compared to what goes on in fopen. > Even if that code is in the innermost of inner loops, the "optimization" > will still be unnoticable. I know it's just an example of an > assignment within a boolean expression, but I see a *lot* of programs > with that same code. Are we really gaining anything, or is it > merely psychological? Heck, 500 nanoseconds is significant, isn't it? :-) Besides, you can save four bytes per test. I'll bet it makes a disk block or two of difference. And we all need all the space we can get, right? :-) Seriously, the difference in the fopen call is pretty small, but the difference in something like for (...) for (...) { if ((j = (k >> 2) - m) == 0) k++; } can be important. Once you get into the habit of testing the results of an assignment, it doesn't even look funny anymore. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 4251) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@maryland