Laurent Monin wrote:
> Oscar Miras a écrit :
>> Hi all,
>>
> Hi Oscar,
>> Sometimes in geeqie code I find things like this:
>> In pan-util.c ; pan_calendar_computer function
>>
> No such function in pan-util.c.
> Though there's a pan_calendar_compute(),  in pan-calendar.c at line 189 
> (current trunk).
>> dt -= 60 * 60 * 24;
>>
>> That could be substituted by a constant ( 86400).
>> I suppose that's left that way to help programmers to understand the code.
> True.
>> But it implies CPU time to do the calculation.
> False.
> 
>> Maybe compiler when reaches that line, automatically do the 
>> calculating, so in execution time that instruction is always processed 
>> as dt -= 86400. I don't know.
>>
> True. You can verify by yourself examing generated assembler code (ie. 
> using gcc -S).
>> Should I leave that way, or now that I'm 'doxygenating' some code, 
>> could I substitute it for dt -= 86400 /** 60 * 60 * 24 */  ?
>>
>>
> Useless in this case.
> Keep it as is, it is readable and doesn't need further optimization.
> 
> 
> Please do not attempt to over-optimize, or if needed, please use tools 
> to measure execution speed changes.
I second this; premature optimization often leads to needlessly-complicated 
code.  If code is slow and you're not sure why, use tools or techniques to 
gather data and figure out why.  Optimizing things randomly often isn't helpful.

Also, compilers are pretty good at optimization these days.  You can assume 
off-the-bat that a compiler will take care of constant expressions (the value 
of 
"60*60*24" will never change) at compile time.  And as zas pointed out, if 
you're not sure what the compiler produces, you can always check.

--xsdg


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Geeqie-devel mailing list
Geeqie-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geeqie-devel

Reply via email to