timeR {NNbenchmark} | R Documentation |
A R6 Class to represent a timer.
Description
timer is a R6 Class that represent a timer. This is a modified version of the
timeR
package for an internal use. Full credit is to Yifu Yan, the author
of the timeR
package.
Value
getTimer
returns a data frame with all records saved by the timer
object. Columns in the data.frame are: event, start, end, duration, RMSE,
MAE, stars, params, comment.
Public Methods
initialize(time,event,verbose,eventTable)
Initialize a timer object. You can also use
createTimer()
function to initialize a timer object.start(eventName)
Start timing for a event,
eventName
should be a stringstop(eventName)
Stop timing for a event.
getTimer()
Get/Print a data.frame with all records.
removeEvent(eventName)
Remove an given row in the eventTable.
toggleVerbose()
Toggle between
TRUE
andFALSE
forverbose
getStartTime()
Get start time for a selected event.
getStopTime()
Get stop time for a selected event.
getDuration()
Get duration for a selected event.
getRMSE()
Get the RMSE for a selected event.
getMAE()
Get the MAE for a selected event.
getStars()
Get stars for a selected event.
getParams()
Get params for a selected event.
getComment()
Get comment for a selected event.
getEventf()
Get entire row for a selected event.
print()
Custom print method for timer class. However, you don't need to use this function to generate custom printing. Custom printing is triggered by default.
Private Methods
slprint(msg, flag = self$verbose)
A function that controls whether to print extra message.
Public fields
time
A POSIXct/POSIXlt value of your latest timing.
event
A string of your latest timing.
eventTable
A data frame that stores all timings.
verbose
A printing setting that controls whether to print messages.
Active bindings
time
A POSIXct/POSIXlt value of your latest timing.
event
A string of your latest timing.
Methods
Public methods
Method new()
Usage
timeR$new(verbose = TRUE)
Method start()
Usage
timeR$start(eventName)
Method stop()
Usage
timeR$stop(eventName, RMSE = NA_real_, MAE = NA_real_, stars = NA_character_, params = NA_character_, comment = NA_character_, printmsg = TRUE)
Method getTimer()
Usage
timeR$getTimer(...)
Method removeEvent()
Usage
timeR$removeEvent(eventName)
Method toggleVerbose()
Usage
timeR$toggleVerbose(...)
Method getStartTime()
Usage
timeR$getStartTime(eventName)
Method getStopTime()
Usage
timeR$getStopTime(eventName)
Method getDuration()
Usage
timeR$getDuration(eventName)
Method getRMSE()
Usage
timeR$getRMSE(eventName)
Method getMAE()
Usage
timeR$getMAE(eventName)
Method getStars()
Usage
timeR$getStars(eventName)
Method getParams()
Usage
timeR$getParams(eventName)
Method getComment()
Usage
timeR$getComment(eventName)
Method getEvent()
Usage
timeR$getEvent(eventName)
Method print()
Usage
timeR$print(...)
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
timer <- createTimer()
timer$start("event1")
## put some codes in between, for instance
Sys.sleep(1)
timer$stop("event1", RMSE = 1, MAE = 1.3, stars = "*",
params = "maxiter=100, lr=0.01", comment = "OK for 1",
printmsg = TRUE)
timer$start("event2")
## put some codes in between, for instance
Sys.sleep(2)
timer$stop("event2", RMSE = 2, MAE = 2.6, stars = "**",
params = "maxiter=1000, lr=0.001", comment = "OK for 2",
printmsg = FALSE)
table1 <- getTimer(timer)
timer$toggleVerbose() # set verbose to FALSE as default is TRUE
table1 # print all records in a data frame
## get attributes for selected events
timer$getStartTime("event1")
timer$getStopTime("event1")
timer$getDuration("event1")
timer$getComment("event1")
timer$getEvent("event1")