[Rd] function call overhead

Hadley Wickham hadley at rice.edu
Wed Feb 16 21:53:54 CET 2011


On Wed, Feb 16, 2011 at 12:13 PM, Paul Gilbert
<pgilbert at bank-banque-canada.ca> wrote:
> (subject changed from: RE: [Rd] Avoiding name clashes: opinion on best practice naming  conventions)
>
> Dominick
>
> Is this really true? Is there a speed advantage to defining a local function this way, say, within another function, and then calling it within a loop rather than the original? Do you have data on this?

I wondered about this statement too but:

> system.time(replicate(1e4, base::print))
   user  system elapsed
  0.539   0.001   0.541
> system.time(replicate(1e4, print))
   user  system elapsed
  0.013   0.000   0.012

So it is (relatively) significant, although it's not going to make an
impact unless you're doing thousands of function calls.

Hadley


-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/



More information about the R-devel mailing list