From hadley at rice.edu  Wed Feb 16 21:53:54 2011
From: hadley at rice.edu (Hadley Wickham)
Date: Wed, 16 Feb 2011 14:53:54 -0600
Subject: [Rd] function call overhead
In-Reply-To: <6441154A9FF1CD4386AF4ABF141A056D21525F40@WMEXOSCD2-N1.bocad.bank-banque-canada.ca>
References: <4d5b98ec.4c02cc0a.13fe.476c@mx.google.com>
	<AANLkTimdA=ExqfGGVuzk703PAs2eMcU_87rj1fydccx-@mail.gmail.com>
	<6441154A9FF1CD4386AF4ABF141A056D21525F40@WMEXOSCD2-N1.bocad.bank-banque-canada.ca>
Message-ID: <AANLkTi=f0j5TXZ=pu6rsFUXLmrAYHWjdTDOy24MDUZ2w@mail.gmail.com>

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/



[Rd] function call overhead
Hadley Wickham