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 ("ns"), microseconds ("us"), milliseconds ("ms"), seconds ("s"), or auto ("auto")

...

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:

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

fibonacci

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)

[Package RcppClock version 1.1 Index]