[R] Timings of function execution in R [was Re: R in Industry]
Frank E Harrell Jr
f.harrell at vanderbilt.edu
Fri Feb 9 18:35:42 CET 2007
Thomas Lumley wrote:
> On 2/9/07, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>>> The other reason why pmin/pmax are preferable to your functions is that
>>> they are fully generic. It is not easy to write C code which takes into
>>> account that <, [, [<- and is.na are all generic. That is not to say that
>>> it is not worth having faster restricted alternatives, as indeed we do
>>> with rep.int and seq.int.
>>>
>>> Anything that uses arithmetic is making strong assumptions about the
>>> inputs. It ought to be possible to write a fast C version that worked for
>>> atomic vectors (logical, integer, real and character), but is there
>>> any evidence of profiled real problems where speed is an issue?
>
>
> I had an example just last month of an MCMC calculation where profiling showed that pmax(x,0) was taking about 30% of the total time. I used
>
> function(x) {z <- x<0; x[z] <- 0; x}
>
> which was significantly faster. I didn't try the arithmetic solution. Also, I didn't check if a solution like this would still be faster when both arguments are vectors (but there was a recent mailing list thread where someone else did).
>
>
> -thomas
I looked in all the code for the Hmisc and Design packages and didn't
find a single example where pmin or pmax did not have 2 arguments. So I
think it is important to have pmin2 and pmax2.
Frank
>
> Thomas Lumley Assoc. Professor, Biostatistics
> tlumley at u.washington.edu University of Washington, Seattle
--
Frank E Harrell Jr Professor and Chair School of Medicine
Department of Biostatistics Vanderbilt University
More information about the R-help
mailing list