if(false) vs if(isNaN) benchmark

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Thu Jul 4 05:53:38 PDT 2013


Hi all,

A trivial little benchmark for comparing the performance of a function using
if(!booleanValue) as a conditional, versus one using if(isNan(x)).

Run with dmd -O -release -inline -noboundscheck on my system, I find the two are
virtually equivalent, with it taking about 30ms for 1 million if(!boolean)
versus about 31 for a million if(isNaN(floatingpoint)).

With ldmd2 and the same optimizations, I get about 25 compared to 27-28 ms for
the two cases, again with a million realizations of each.

Finally, with gdmd I get 30ms for a million if(!boolean) versus about 150ms for
a million if(isNaN(floatingpoint)).

Code attached, feel free to critique.  Generally I think these results show that
the difference between checking a boolean and checking isNan are negligible, but
I'm surprised at the relatively bad performance with gdmd and I wonder if
there's some particular reason for this.

The relevance is to a fix I'm preparing for this bug:
http://d.puremagic.com/issues/show_bug.cgi?id=10322

See also: http://forum.dlang.org/post/lcrwybqszclitzravrqo@forum.dlang.org

Thanks in advance for any feedback :-)

Best wishes,

    -- Joe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: isnan.d
Type: text/x-dsrc
Size: 672 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20130704/b11ae0b5/attachment.d>


More information about the Digitalmars-d-learn mailing list