newTimer | R Documentation |
newTimer()
sets up a timer object with two
internal state variables, namely count
to count the number of timer calls and
tUsed
to calculate the total time spent in a code block
between two timer calls.
newTimer()
Generate a timer:
a<-newTimer()
sets up the timer a()
.
The timer a()
supports three methods:
a()
or
a("Measure")
or
a(method="Measure")
starts the timer when called 1st, 3rd, 5th, ... time
and stops the timer
when called the 2nd, 4th, 6th, ... time.
The calls can be manually inserted
before and after a block of R-code for profiling.
a("TimeUsed")
or
a(method="TimeUsed")
returns the time used in seconds.
a("Count")
or
a(method="Count")
returns the number of times
the function/block or R-code has been executed.
The second way of usage is with the Timed()
function:
Generate a timer:
a<-newTimer()
sets up the timer a()
.
You convert a function b()
into a timed function
bTimed()
by
bTimed<-Timed(a, b)
.
You use bTimed()
instead of b()
.
At the end, you can query the aggregated time and
the aggregated number of executions by
a("TimeUsed")
and
a("Count")
, respectively.
newTimer()
returns a timer function.
a_timer_function()
returns the used time in seconds
(invisible).
a_timer_function("TimeUsed")
returns the used time in seconds.
a_timer_function("Count")
returns the number of executions
of a timed function and/or a timed block of R-Code in seconds.
Other Performance Measurement:
Counted()
,
Timed()
,
newCounter()
a<-newTimer()
a(); Sys.sleep(2); a()
a("TimeUsed")
a("Count")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.