Package 'timer'

Title: R6 Timer
Description: A simple timer as an R6 class. The timer has four functions: start(), stop(), reset() and elapsed(). The elapsed() function returns the elapsed wall clock time (as opposed to CPU time) as an object of class lubridate::Duration.
Authors: Joe Thorley [aut, cre] , Poisson Consulting [fnd, cph]
Maintainer: Joe Thorley <[email protected]>
License: MIT + file LICENSE
Version: 0.0.1.9000
Built: 2024-11-21 06:38:03 UTC
Source: https://github.com/poissonconsulting/timer

Help Index


Is Timer

Description

Tests whether x is an object of class Timer.

Usage

is.timer(x)

Arguments

x

The object to test.

Value

A flag indicating whether the test was positive.


R6 Timer Class

Description

A simple timer as an R6 class.

The timer has four functions: $start(), $stop(), $reset() and $elapsed(). The $elapsed() function returns the elapsed wall clock time (as opposed to CPU time) as an object of class lubridate::Duration.

Format

An R6Class generator object.

Methods

Public methods


Method is_running()

Usage
Timer$is_running()

Method elapsed()

Usage
Timer$elapsed()

Method reset()

Usage
Timer$reset()

Method start()

Usage
Timer$start()

Method stop()

Usage
Timer$stop()

Method clone()

The objects of this class are cloneable with this method.

Usage
Timer$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples

# instantiate a new timer
timer <- Timer$new()

# no time has elapsed because the timer has not started
timer$elapsed()

# start the timer
timer$start()

# get the time elapsed (as an object of class lubridate::Duration)
# time elapsed is increasing because the timer is still running
timer$elapsed()
timer$elapsed()

# stop the timer
timer$stop()

# time elapsed is now fixed
timer$elapsed()
timer$elapsed()

# because timer is an object of class R6 use the clone() function
# to make a copy
timer2 <- timer$clone()

# reset the timer
timer$reset()
timer$elapsed()

# timer2 is not reset
timer2$elapsed()