I am trying to find how long a specific subset of code takes in cmprsk and so I would like to place t0 = Sys.time()
at one location, t1 = Sys.time()
in another location, and then print out the difference via cat(sprintf("time taken %f seconds", as.numeric(t1-t0, units="secs"))
.
I know from print(as.list(body(crr)))
that the positions for timing would be at=2
and at=28
. I use the following lines to place the trace
s in:
trace(crr, 't0 = Sys.time();', at=2);
trace(crr, 't1 = Sys.time();', at=28);
trace(crr, 'cat(sprintf("time taken = %f", as.numeric(t1-t0, units="secs")));', at=40);
However, when I run the code, it looks like only the last trace
is being used. When I run the script and grep
for Trace
, I get the following:
Loading required package: splines
(loaded the methods namespace)
Tracing function "crr" in package "cmprsk"
Tracing function "crr" in package "cmprsk"
Tracing function "crr" in package "cmprsk"
.doTrace("cat(sprintf(\"time taken = %f\", as.numeric(t1-t0, units=\"secs\")));",
Does this indicate that only the last trace
is being kept? If so, how do I put more than one trace
in the original function?