From ripley at stats.ox.ac.uk  Fri Apr 30 10:03:09 2010
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri, 30 Apr 2010 09:03:09 +0100 (BST)
Subject: [Rd] S4 method execution time
In-Reply-To: <o2r48f8cced1004300016t994e3429l2b23dae96e3c19d3@mail.gmail.com>
References: <o2r48f8cced1004300016t994e3429l2b23dae96e3c19d3@mail.gmail.com>
Message-ID: <alpine.LFD.2.00.1004300856590.19781@gannet.stats.ox.ac.uk>

On Fri, 30 Apr 2010, Daniel Murphy wrote:

> Hello:
>
> I have written some an elementary S4 classes around a matrix to strengthen
> control of some key attributes. When I run a fairly elementary function
> ("f") on the matrix outside the class it runs instantaneously (elapsed
> system.time = 0) but when I setMethod "f" on myClass -- returning an
> instance of myClass -- it runs perceptibly slower (elapsed system.time =
> .06). I suspect my initialization and/or validity functions are
> inefficiently written. I thought I read in this list of a function that will
> trace the execution time of each of the functions called during the
> evaluation of an R expression, but now I can't find that message. Is there
> such a function, or was I mistaken?

Maybe Rprof?   That is certainly the tool I would use, and it is 
described in 'Writing R Extensions'.

But we do know that S4 methods do have a significant overhead: OTOH 
there is caching going on and so a lot of this overhead is on first 
use.  So you may find that your 'toy' test does not scale to a real 
problem (surely you have difficulty perceiving 60ms, literally the 
blink of an eye?).

>
> Thank you.
>
> Dan Murphy
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] S4 method execution time
Prof Brian Ripley