Re: [Rd] Proposed speedup of ifelse

2018-05-07 Thread Hugh Parsonage
Thanks Gabe, and yes happy for you to submit the patch. Some thoughts I've had in the interim: 1. Matt Dowle encouraged me to submit a patch as it could improve the CRAN check farm timings since `ifelse` is presumably used a lot. I thought the biggest benefit might come by improving the speed whe

Re: [Rd] Proposed speedup of ifelse

2018-05-07 Thread Gabe Becker
Hugh, (Note I speak for myself only and not for R-core) Thanks for looking into this. I think it's great to have community members that are interested in contributing to R and helping it continue to get better. And I think, and my local experiments bear out, that using anyNA as a fastpass conditi

Re: [Rd] Proposed speedup of ifelse

2018-05-03 Thread Hugh Parsonage
Thanks Radford. I concur with all your points. I've attempted to address the issues you raised through the github.io post. The new method appears to be slower for test lengths < 100 and possibly longer lengths (not just < 10). Of course length(test) < 100 is very quick, so I simply added this to t

Re: [Rd] Proposed speedup of ifelse

2018-05-03 Thread Radford Neal
> I propose a patch to ifelse that leverages anyNA(test) to achieve an > improvement in performance. For a test vector of length 10, the change > nearly halves the time taken and for a test of length 1 million, there > is a tenfold increase in speed. Even for small vectors, the > distributions of t

Re: [Rd] Proposed speedup of ifelse

2018-05-02 Thread Hugh Parsonage
And the patch itself: --- a/src/library/base/R/ifelse.R +++ b/src/library/base/R/ifelse.R @@ -18,12 +18,14 @@ ifelse <- function (test, yes, no) { + attributes_of_test <- attributes(test) + if(is.atomic(test)) { # do not lose attributes if (typeof(test) != "logical") storage.mo

[Rd] Proposed speedup of ifelse

2018-05-02 Thread Hugh Parsonage
I propose a patch to ifelse that leverages anyNA(test) to achieve an improvement in performance. For a test vector of length 10, the change nearly halves the time taken and for a test of length 1 million, there is a tenfold increase in speed. Even for small vectors, the distributions of timings bet