[R] interpreting profiling output

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Jul 25 18:22:04 CEST 2004


Kasper Daniel Hansen <k.hansen at biostat.ku.dk> writes:

> I have some trouble interpreting the output from profiling. I have
> read the help pages Rprof, summaryRprof and consult the R extensions
> manual, but I still have problems understanding the output.
> 
> Basically the output consist of self.time and total.time. I have the
> understanding that total.time is the time spent in a given function
> including any subcalls or child functions or whatever the technical
> term for that activity is. In contrasts self.time is the time spent in
> the function excluding subcalls.
> 
> Now, in my understanding basically everything in R is functions. I
> would then guess that for almost any function (except the "atomic
> ones") the self.time would be very small as it would spend most of its
> time calling other functions (again, since almost everything is a
> function). So how do R determine when a subfunction is called?
...brutal snippage...
> I guess some of the answers would be clear if I had a firm grasp of
> the inner workings of R :)

In a word, yes... 

The profiling keeps track of R's *context stack* which is not quite
the same as function calls. Essentially, it only counts R functions that
are actually written in R, but not .Internal, .Primitive, etc. So
"self" counts the amount of time that a function was at the top of the
stack. This is done by a periodic poll which dumps out the context
stack at regular intervals. Seeing cases where the self percentages
don't add to 100% is, I believe, simply due to truncation of the tails
-- that is, there is a large number of different functions which each
are counted a few times, and these are not shown in the summary output.

[Sorry about the late reply, but I was out of town, and noone seems to
have answered this.]

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list