A set of functions provides access to the spdlog
stopwatch
facilty. As stopwatch
object is a simple container around a
C++ std::chrono
object which (essentially) reports
elapsed-time since creation. The object is exported to R via an external
pointer permitting use from both R and C++.
get_stopwatch()
elapsed_stopwatch(sw)
format_stopwatch(sw)
# S3 method for class 'stopwatch'
print(x, ...)
# S3 method for class 'stopwatch'
format(x, ...)
sw
|
An S3 object of type stopwatch .
|
x
|
An S3 object of type stopwatch .
|
…
|
Dotted argument required by generic, unused here. |
Several functions are provided:
get_stopwatch
elapsed_stopwatch
format_stopwatch
The stopwatch
object has print
and
format
methods.
The desired object is returned: respectively, a stopwatch object as an external pointer in an S3 class, the elapsed time in seconds as a double, or formatted as a character variable.
library("RcppSpdlog")
w <- get_stopwatch()
Sys.sleep(0.2)
elapsed_stopwatch(w)
[1] 0.2009362
format_stopwatch(w)
[1] "0.201288"