RcppClock {RcppClock} | R Documentation |
RcppClock
Description
Time Rcpp functions and summarize, print, and plot runtime statistics
Usage
## S3 method for class 'RcppClock'
summary(object, units = "auto", ...)
## S3 method for class 'RcppClock'
print(x, ...)
## S3 method for class 'RcppClock'
plot(x, ...)
Arguments
object |
RcppClock object |
units |
nanoseconds ( |
... |
arguments to other functions |
x |
RcppClock object |
Details
See https://github.com/zdebruine/RcppClock/readme.md for information on how to use the package.
RcppClock functions
See the RcppClock README on https://github.com/zdebruine/RcppClock#readme
for basic usage examples.
When the Rcpp Rcpp::clock::stop()
method is called in Rcpp code, an S3 RcppClock
object
will be created in the global environment. This object contains three methods:
-
summary
: computes runtime summary statistics and returns adata.frame
-
print
: runssummary
and then prints the resultingdata.frame
-
plot
: a ggplot2 violin plot with jitter points showing runtimes for each expression
The fibonacci
function is a simple example of how to use RcppClock.
See the source code on github.com/zdebruine/RcppClock/src/fibonacci.cpp
See Also
Examples
library(RcppClock)
fibonacci(n = 25:35, reps = 10)
# this function creates a global environment variable "clock"
# that is an S3 RcppClock object
clock
plot(clock)
summary(clock, units = "ms")
## Not run:
# this is the Rcpp code behind the "fibonacci" example function
```{Rcpp}
//[[Rcpp::depends(RcppClock)]]
#include <RcppClock.h>
int fib(int n) {
return ((n <= 1) ? n : fib(n - 1) + fib(n - 2));
}
//[[Rcpp::export]]
void fibonacci(std::vector<int> n, int reps = 10) {
Rcpp::Clock clock;
while(reps-- > 0){
for(auto number : n){
clock.tick("fib" + std::to_string(number));
fib(number);
clock.tock("fib" + std::to_string(number));
}
}
clock.stop("clock");
}
```
## End(Not run)