Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

Re: Question on performance



On Sat, Oct 9, 2010 at 4:40 AM, Paul Zimmermann
<Paul.Zimmermann@xxxxxxxx> wrote:
>       Dan,
>
>>       That will work well.  Not as efficient as not doing it,
>>       of course, but more efficient than you think.  Modern
>>       compilers are pretty routinely inlining that sort of
>>       thing so it should go better than even a simple user
>>       function call.  In fact, to aid it along, rather than
>>       writing it as a function call you might consider just
>>       using a #define.  Something like:
>>
>> #define nan2zero(x) ((isnan(x))?0.0:x)
>>
>>       Then there is no function call in the first place.
>
> with gcc -O3 writing a function gives no slowdown, since gcc is quite good
> at automatic inlining.
>

But one rarelly compiles everything at -O3 instead of -O2.
-O2 is the "default", and recommended optimization level.
(Efficiency of codes generated by GCC is not monotonic in -On.)

However, I will also note that for a C++ (and C99) implementation, I will
expect most "simple" functions to be inline as opposed to macros.