Click here to Skip to main content
16,015,991 members

Survey Results

Do you optimise your code?   [Edit]

Survey period: 29 Nov 2004 to 5 Dec 2004

Do you optimise your code for speed, size or resource use? Or do you just let it all hang out?

OptionVotes% 
Yes, all the time27219.22
Yes, whenever I have the time or resources42930.32
Only when it's critical I do so45131.87
Occasionally1319.26
Never: I have no time or resources332.33
Never. What's the point?211.48
Never. I've never learned how.785.51



 
GeneralAll the time, or on a second pass at a minimum... Pin
James R. Twine29-Nov-04 5:01
James R. Twine29-Nov-04 5:01 
GeneralRe: All the time, or on a second pass at a minimum... Pin
patnsnaudy29-Nov-04 8:49
patnsnaudy29-Nov-04 8:49 
GeneralNetwork code... Pin
Navin29-Nov-04 3:04
Navin29-Nov-04 3:04 
GeneralOnly when needed Pin
ed welch29-Nov-04 2:36
ed welch29-Nov-04 2:36 
GeneralRe: Only when needed Pin
Jörgen Sigvardsson30-Nov-04 11:02
Jörgen Sigvardsson30-Nov-04 11:02 
GeneralGood programming style Pin
Roger Allen29-Nov-04 2:26
Roger Allen29-Nov-04 2:26 
GeneralRe: Good programming style Pin
Jim A. Johnson29-Nov-04 7:04
Jim A. Johnson29-Nov-04 7:04 
GeneralRe: Good programming style Pin
Jeff J29-Nov-04 8:06
Jeff J29-Nov-04 8:06 
He can't be a rabid over-optimiser if he doesn't use const, he probably just fancies himself as an optimiser.

Const references are one of the most important optimisation hints, without which, the [compiler's] optimiser may just toss dice to decide which objects and pointers to keep in registers. VC++ no longer honours the register keyword, so const is all we have left.

To the optimiser, const is somewhat the opposite of register; instead of keeping the object in a register, it may specifically decide that object does not need to be, since it never changes. Thus, other objects are more likely to be kept in registers. Since more than one operation can execute on modern chips at once, things can be assigned from stack vars with little or no loss if there's something else that can be done in the meantime. But that's only part of the story.

const objects may also be temporary, can be calculated as needed (sometimes concurrently with other operations, to promote parallelism, which can double efficiency), and provide several other hints. In other words, const is an invaluable optimisation hint. If this guy really loves to optimise (he really should be judicious, since many things are done automatically by the compiler), he would step through critical loops in disassembly view as I do, and notice the benefits.

Personally, I've found const saved my arse many times, too. In coding frenzies (read "deadline"), I've occassionally had the compiler squawk that I tried to modify a const object, which forces me to fix it and avoid nasty bugs.

Cheers
GeneralRe: Good programming style Pin
Jörgen Sigvardsson30-Nov-04 11:08
Jörgen Sigvardsson30-Nov-04 11:08 
GeneralRe: Good programming style Pin
Nemanja Trifunovic30-Nov-04 12:47
Nemanja Trifunovic30-Nov-04 12:47 
GeneralRe: Good programming style Pin
Jörgen Sigvardsson30-Nov-04 13:07
Jörgen Sigvardsson30-Nov-04 13:07 
GeneralRe: Good programming style Pin
Jeff J30-Nov-04 17:36
Jeff J30-Nov-04 17:36 
GeneralRe: Good programming style Pin
Jeff J30-Nov-04 17:01
Jeff J30-Nov-04 17:01 
GeneralRe: Good programming style Pin
Jim A. Johnson1-Dec-04 5:27
Jim A. Johnson1-Dec-04 5:27 
GeneralRe: Good programming style Pin
Nemanja Trifunovic1-Dec-04 6:47
Nemanja Trifunovic1-Dec-04 6:47 
GeneralRe: Good programming style Pin
Jeff J1-Dec-04 10:36
Jeff J1-Dec-04 10:36 
GeneralRe: Good programming style Pin
Nemanja Trifunovic2-Dec-04 2:07
Nemanja Trifunovic2-Dec-04 2:07 
GeneralRe: Good programming style Pin
Jeff J2-Dec-04 9:14
Jeff J2-Dec-04 9:14 
GeneralRe: Good programming style Pin
Jeff J1-Dec-04 10:33
Jeff J1-Dec-04 10:33 
GeneralRe: Good programming style - const Pin
Bamaco229-Nov-04 9:59
Bamaco229-Nov-04 9:59 
GeneralRe: Good programming style - const Pin
Shog929-Nov-04 10:33
sitebuilderShog929-Nov-04 10:33 
GeneralRe: Good programming style - const Pin
Bamaco229-Nov-04 11:18
Bamaco229-Nov-04 11:18 
GeneralRe: Good programming style - const Pin
zorrer29-Nov-04 20:09
zorrer29-Nov-04 20:09 
GeneralOnly if Pin
Yulianto.28-Nov-04 21:43
Yulianto.28-Nov-04 21:43 
GeneralOnly if Pin
Navin29-Nov-04 3:02
Navin29-Nov-04 3:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.