Click here to Skip to main content
15,920,956 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 
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 
Michael Dunn wrote:
he flat-out hated the idea of an extra if, he wanted it all on one line, unless he could "be sure the generated code was faster."

Talk about inability to prioritise! If the code were in a loop that iterated hundreds of times, maybe, but actually your suggestion is already more optimal than the usual alternative:

if ( bIsURL )
   cf.whatever = ( some_value | CF_SOMEFLAG );
else
   cf.whatever = some_value;
Or the one-line equivalent (same compiler output):
cf.whatever = bIsURL ? ( some_value | CF_SOMEFLAG ) : some_value;
You're code is much tighter, as if it even matters in this case!
If he's an assembler junky, show him this (in pseudo x86 assembler):
  TEST  bIsURL, bIsURL
  JZ    not_url
  MOV   EAX, some_value
  OR    EAX, CF_SOMEFLAG    ; stall - must wait on EAX
  MOV   [cf.whatever], EAX  ; stall - wait on EAX again
  JMP   done                ; needless jump
not_url:
  MOV   [cf.whatever], some_value
done:
As compared to your suggested code:
  MOV   [cf.whatever], some_value   ; very fast
  TEST  bIsURL, bIsURL
  JZ    done
  OR    [cf.whatever], CF_SOMEFLAG  ; very fast
done:
Even if he's an eliminate-the-branches freak (which I doubt), the alternative on one line is not necessarily a win, and readability is lost with no realistic performance gain:
cf.whatever = ( some_value | (-(int)bIsURL & CF_SOMEFLAG) );
He needs to put the effort where it's needed, lose the attitude, and show some appreciation.

Cheers
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.