Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!snorkelwacker.mit.edu!hsdndev!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.lang.c Subject: Re: May too many register variables hurt? (was Re: Novice question.) Message-ID: <10571:Nov3008:33:3090@kramden.acf.nyu.edu> Date: 30 Nov 90 08:33:30 GMT References: <976@mwtech.UUCP> <9733:Nov2722:02:3090@kramden.acf.nyu.edu> Organization: IR Lines: 49 In article rjc@uk.ac.ed.cstr (Richard Caley) writes: [ void tweakit(register struct foobar *lastone) ] [ vs. void tweakit(struct foobar *lastone) ] > I find the second _so_ much more readable Oh, fgs. I find both of them equally unreadable. With pre-ANSI syntax, it's trivial to see the variable right near the end of a line, and to work backwards through its declaration to see how it's used. (How else can you read a declaration?) Adding ``register'' or another keyword to the beginning of a line hardly impairs this skill. > that adding in the register > for, say, a 10% speedup in a program which runs in 10 seconds is not > worth it unless you are _very_ sure that that second is critical and > the code is more or less totally stable. Well, fine. In every program's life there comes a time when it must inspect itself, and say, ``Yea, verily, my registers are hardly used, and it is time for me to give up the slowness of immaturity, and take on some register declarations, so that I can run at a respectable speed, until death do us part.'' Or something like that. I'm just tidying up a program whose main code has 19 register declarations. I knew as I added each of those variables that it would be used a few times in the inner loop, and the nature of the problem meant that none of the variables would be used much more often than the others. Should I take away any of those declarations? Don't be silly. Did I have to wait for the code to be stable to do this optimization? Not at all. What happens when I remove the declarations? With optimization, nothing. Without optimization, #define register null makes it run 40-80% slower. You have to be crazy to say that programmers should take such a penalty during development, for no more reason than ``register looks ugly'' or ``it *could* slow down your code.'' > If the time _is_ critical then it is not enough to stick in a few > register variables anyway, it is time to wheel out the profiler, stare > at the assembler output and work out whether floating point arithmetic > or jumps are more time critical on your machine. True. Every optimization helps. ---Dan