Click here to Skip to main content
16,016,024 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



 
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 
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 
Nemanja Trifunovic wrote:
But hey, if the only way to make a guy use consts is to tell him it is good for optimizations, then just tell him it is good for optimizations

Child psychology for übergeeks 101.. Big Grin | :-D

When I think about it, const can be used as a tool for optimization. You can pass object parameters as const references, thus forcing the function to not modify the parameter or make a copy of it before it can do any modifications. 4 bytes on the stack vs X > 4 is an optimization I guess. But it's hardly because of some compiler magic, it's a purely hardware thingie.

Hmm.. a const ref is probably 8 bytes big on a IA-64 machine. Which could mean that passing const refs on such hardware is potentially less efficient than passing the entire object if it's smaller than 8 bytes. Unsure | :~ I can already see optimizing geeks writing macros like
#ifdef __IA64__
#define CONST_REF(T) const T
#else
#define CONST_REF(T) const T&
#endif
 
void MyIA64OptimizedFunction(CONST_REF(ClassName) param)
{
   ...
}
 
// or for the template minded
template <typename T, bool RefYesNo>
struct ConstRefMaybeHelper {
     typedef const T& type;
};
 
template <typename T>
struct ConstRefMaybeHelper<T, false> {
     typedef const T type;
};
 
template <typename T> 
struct ConstRefMaybe {
    typedef ConstRefMaybeHelper<T, sizeof(T) >= sizeof(T*)>::type type;
};
 
void MyMuchCoolerIA64OptimizedFunction(ConstRefMaybe<ClassName>::type param)
{
   ...
}


--
Weiter, weiter, ins verderben.
Wir müssen leben bis wir sterben.

I blog too now[^]

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 
GeneralNever on the first pass Pin
Michael P Butler28-Nov-04 21:22
Michael P Butler28-Nov-04 21:22 
GeneralRe: Never on the first pass Pin
WillemM28-Nov-04 22:12
WillemM28-Nov-04 22:12 

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.