newTimer: Timer for R code chunks.

View source: R/timer.R

newTimerR Documentation

Timer for R code chunks.

Description

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.

Usage

newTimer()

Details

  • Generate a timer: a<-newTimer() sets up the timer a(). The timer a() supports three methods:

    1. 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.

    2. a("TimeUsed") or a(method="TimeUsed") returns the time used in seconds.

    3. 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:

    1. Generate a timer: a<-newTimer() sets up the timer a().

    2. You convert a function b() into a timed function bTimed() by bTimed<-Timed(a, b).

    3. You use bTimed() instead of b().

    4. At the end, you can query the aggregated time and the aggregated number of executions by a("TimeUsed") and a("Count"), respectively.

Value

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.

See Also

Other Performance Measurement: Counted(), Timed(), newCounter()

Examples

   a<-newTimer() 
   a(); Sys.sleep(2); a()
   a("TimeUsed")
   a("Count")

xegaSelectGene documentation built on April 16, 2025, 5:12 p.m.