[Rcpp-devel] Rcpp ISNAN slower than C ISNAN?

Christian Gunning xian at unm.edu
Thu Dec 15 04:47:55 CET 2016

On Wed, Dec 14, 2016 at 12:23 PM, Johannes Kruisselbrink
<johannes at kruisselbrink.eu> wrote:
> Good point. Actually, I didn't even realize there were so many is-nan
> functions to choose from. But indeed, we used the R-core ISNAN function on
> doubles accessed via Rcpp.

Me either :)
Of course, the above isn't particular to Rcpp, but I found that
tracking down the underlying machinery of ISNAN in the context of Rcpp
to be an interesting and useful exercise.

>> Based on the above, I added permutations to a *very* minimal test (no
>> return val, etc) that include Romain's suggestion:
>> https://github.com/helmingstay/rcpp-timings/tree/master/minimal
>> ## source('benchmarks.r')
> Wow, thank you for the thorough comparison. I ran some tests myself based on
> your code. It seems that I cannot get the "CountNans_expr" version to
> compile, any ideas?  Same problem with the Rcpp sugar isnan version.

Can you be more specific?

> The std::isnan version, however, does work and, on my machine, actually
> outperforms the call function. So performance-wise this is a very
> interesting candidate.

Just to clarify, R's NA is subset of ieee NaN.  So std::isnan catches
both NAs and NaNs.  If you need to manually catch *just* NAs, then it
looks like you need to return to an R-core solution (please do correct
me if I muxed this up).
Ref: https://github.com/wch/r-source/blob/trunk/src/main/arithmetic.c#L108


A man, a plan, a cat, a ham, a yak, a yam, a hat, a canal – Panama!

More information about the Rcpp-devel mailing list