[Rd] speed up R_IsNA, R_IsNaN for vector input
Jan Gorecki
j@goreck| @end|ng |rom w|t@edu@p|
Sun Sep 29 13:09:55 CEST 2019
Dear R developers,
I spotted that R_isNA and R_IsNaN could be improved when applied on a
vector where we could take out small part of their logic, run it once,
and then reuse inside the loop.
I setup tiny plain-C experiment. Taking R_IsNA, R_IsNaN from R's
arithmetic.c, and building R_vIsNA and R_vIsNaN accordingly.
For double input of size 1e9 (having some NA and NaN) I observed
following timings:
R_IsNA 6.729s
R_vIsNA 4.386s
R_IsNaN 6.874s
R_vIsNaN 4.479s
ISNAN 4.392s
It looks like R_vIsN(A|aN) are close to ISNAN (which just wraps to
math.h::isnan).
Should I follow up with a patch?
The experiment is a single nan.c file of 127 lines (includes R C
funs). Large enough to not paste in the email. Here is the link:
https://gist.github.com/jangorecki/c140fed3a3672620c1e2af90a768d785
Run it as:
gcc nan.c -lm
./a.out R_vIsNA 8
./a.out R_IsNA 8
./a.out R_vIsNaN 8
./a.out R_IsNaN 8
./a.out ISNAN 8
Best regards,
Jan Gorecki
More information about the R-devel
mailing list