Click here to Skip to main content
15,920,801 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



 
General-O2 Pin
Saleh Dindar4-Dec-04 20:38
Saleh Dindar4-Dec-04 20:38 
GeneralBut the compiler CANNOT optimize everything! (waS: Re: -O2) Pin
James R. Twine5-Dec-04 7:40
James R. Twine5-Dec-04 7:40 
   But you have to remember that there are things that the compiler simply cannot optimize; for example, unnecessary dynamic resource (memory) management.

   There is lots of code out there that does unnecessary things, but the complier cannot help.  For example, I have seen code similar to this in MSDN as a example (a very BAD one) of how to do custom drawing of text:
<br />
    // ...<br />
    LOGFONT *pFL = new LOGFONT;<br />
    // Do Something With The LOGFONT...<br />
    delete pLF;<br />
    // ...<br />

   (pLF was only used locally.)  And I had seen that code being used to draw multiple lines of text, where pLF was being released and reallocated each time the format changed!  (And how often is drawing code being called?)

   Of course, there is no need to waste CPU time dynamically allocating the LOGFONT object; having one on the stack will work better, because no extra time is wasted with dynamic memory management.

   That is one example of where the compiler cannot optimize that situation.  Same thing when you do something like using a temporary CString object just to format a number in decimal format (a'la "%d"); the compiler cannot optimize away the dynamic memory allocation or the double-pass required by CString to actually build the string. You should be using an appropriately sized stack buffer with itoa(...) or a similar function.

   Not to mention that if you are using external libraries or DLLs, you never know what optimizations were in effect when they were built.

   IMHO, asking a developer to rely on the compiler to fix their mistakes is naive at best, and neglegent at worst.  Developers should have good enough habits in place so that the compiler has less work to do fixing stupid mistakes.

   Peace!

-=- James
Tip for inexperienced drivers: "Professional Driver on Closed Course" does not mean "your Dumb Ass on a Public Road"!
Articles -- Products: Delete FXP Files & Check Favorites

GeneralRe: But the compiler CANNOT optimize everything! (waS: Re: -O2) Pin
Saleh Dindar5-Dec-04 20:52
Saleh Dindar5-Dec-04 20:52 
GeneralOptimise ur Code Now!! Pin
Optimum Speed4-Dec-04 1:16
sussOptimum Speed4-Dec-04 1:16 
GeneralNAAAAAAAAARRRRRRRFFFFFF Pin
wolfibender3-Dec-04 11:25
wolfibender3-Dec-04 11:25 
GeneralRe: NAAAAAAAAARRRRRRRFFFFFF Pin
gaamoa4-Dec-04 9:49
gaamoa4-Dec-04 9:49 
GeneralRe: NAAAAAAAAARRRRRRRFFFFFF Pin
.dan.g.5-Dec-04 12:56
professional.dan.g.5-Dec-04 12:56 
GeneralI can't set my asp.net application on the server Pin
Mahmoud Tahoon3-Dec-04 2:06
Mahmoud Tahoon3-Dec-04 2:06 
GeneralI've seen programming questions in the lounge.... but this is ridiculous! Pin
Luis Alonso Ramos5-Dec-04 11:13
Luis Alonso Ramos5-Dec-04 11:13 
GeneralMoore law is the greatest optimizer Pin
netpaul2-Dec-04 19:15
netpaul2-Dec-04 19:15 
GeneralRe: Moore law is the greatest optimizer Pin
James R. Twine5-Dec-04 7:47
James R. Twine5-Dec-04 7:47 
GeneralMaximize speed! Pin
John R. Shaw2-Dec-04 18:00
John R. Shaw2-Dec-04 18:00 
GeneralRe: Maximize speed! Pin
Michael Dunn4-Dec-04 18:22
sitebuilderMichael Dunn4-Dec-04 18:22 
GeneralIt depends... Pin
J. Dunlap1-Dec-04 16:46
J. Dunlap1-Dec-04 16:46 
GeneralOnly with things the compiler can't help with... Pin
Michael Dunn1-Dec-04 13:23
sitebuilderMichael Dunn1-Dec-04 13:23 
GeneralRe: Only with things the compiler can't help with... Pin
Jeff J1-Dec-04 21:16
Jeff J1-Dec-04 21:16 
GeneralCode optimization is not only a compiler thing... Pin
DiWa3-Dec-04 22:36
DiWa3-Dec-04 22:36 
GeneralQuality Pin
KarstenK30-Nov-04 22:46
mveKarstenK30-Nov-04 22:46 
GeneralCode efficiency and readibility Pin
De Nardis Andrea30-Nov-04 22:03
De Nardis Andrea30-Nov-04 22:03 
GeneralStack Overflow Error! Pin
Hambik30-Nov-04 3:43
Hambik30-Nov-04 3:43 
GeneralRe: Stack Overflow Error! Pin
Jörgen Sigvardsson30-Nov-04 10:56
Jörgen Sigvardsson30-Nov-04 10:56 
GeneralRe: Stack Overflow Error! Pin
Hambik30-Nov-04 23:49
Hambik30-Nov-04 23:49 
GeneralRe: Stack Overflow Error! Pin
avtar30-Nov-04 18:55
avtar30-Nov-04 18:55 
GeneralRe: Stack Overflow Error! Pin
Hambik30-Nov-04 23:47
Hambik30-Nov-04 23:47 
GeneralRe: Stack Overflow Error! Pin
HammerBlade1-Dec-04 1:32
HammerBlade1-Dec-04 1:32 

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.