Skip to content
Back to formatted view

Raw Message

Message-ID: <AANLkTi=f0j5TXZ=pu6rsFUXLmrAYHWjdTDOy24MDUZ2w@mail.gmail.com>
Date: 2011-02-16T20:53:54Z
From: Hadley Wickham
Subject: function call overhead
In-Reply-To: <6441154A9FF1CD4386AF4ABF141A056D21525F40@WMEXOSCD2-N1.bocad.bank-banque-canada.ca>

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/