Package 'rcpptimer'

Title: 'Rcpp' Tic-Toc Timer with 'OpenMP' Support
Description: Provides 'Rcpp' bindings for 'cpptimer', a simple tic-toc timer class for benchmarking 'C++' code <https://github.com/BerriJ/cpptimer>. It's not just simple, it's blazing fast! This sleek tic-toc timer class supports overlapping timers as well as 'OpenMP' parallelism <https://www.openmp.org/>. It boasts a nanosecond-level time resolution. We did not find any overhead of the timer itself at this resolution. Results (with summary statistics) are automatically passed back to 'R' as a data frame.
Authors: Jonathan Berrisch [aut, cre]
Maintainer: Jonathan Berrisch <[email protected]>
License: GPL (>= 3)
Version: 1.2.1
Built: 2024-11-21 05:36:46 UTC
Source: https://github.com/berrij/rcpptimer

Help Index


Simple rcpptimer example

Description

Time the computation of Fibonacci numbers

Usage

fibonacci(n)

Arguments

n

vector giving integers for which to compute the Fibonacci sum

Details

The function being timed is the following:

int fib(int n) { return ((n <= 1) ? n : fib(n - 1) + fib(n - 2)); }

Runtime for computations less than n = 15 is nearly unmeasurable.

Value

vector of integers giving the Fibonacci sum for each element in n

Examples

fibonacci(n = rep(20:25, 10))
# this function creates a global environment variable "times"
times

Simple rcpptimer example using OpenMP

Description

Time the multithreaded computation of Fibonacci numbers

Usage

fibonacci_omp(n)

Arguments

n

vector giving integers for which to compute the Fibonacci sum

Details

The function being timed is the following:

int fib(int n) { return ((n <= 1) ? n : fib(n - 1) + fib(n - 2)); }

Runtime for computations less than n = 15 is nearly unmeasurable.

Value

vector of integers giving the Fibonacci sum for each element in n

Examples

fibonacci_omp(n = rep(20:25, 10))
# this function creates a global environment variable "times"
times

Print method for rcpptimer output

Description

Prints the times object and scales the timings if appropriate. If all timings are smaller than 1 microsecond, the timings are printed in nanoseconds. If the smallest timing is higher than a Millisecond / Seconds / Minutes / Hours, the timings are printed in the unit of that threshold. This behavior can be disabled by setting scale = FALSE.

Usage

## S3 method for class 'rcpptimer'
print(x, scale = TRUE, ...)

Arguments

x

Object of class rcpptimer

scale

Scale the timings and statistics to a more human readable format

...

further arguments are ignored