Table of Contents
Fetching ...

rcpptimer: Rcpp Tic-Toc Timer with OpenMP Support

Jonathan Berrisch

TL;DR

rcpptimer addresses the need to benchmark and profile C++ code executed from R, especially in parallel OpenMP contexts. It introduces a tic-toc timer with support for overlapping and nested timers, automatic return of aggregated results to R, and nanosecond-level resolution. Key contributions include thread-aware timing using per-thread keys, online aggregation via the Welford algorithm, and a destructor-backed automatic stop/return behavior, all within an accessible Rcpp workflow. The tool simplifies profiling of Rcpp code, supports package integration, and is backed by vignettes, tests, and continuous integration for cross-platform reliability.

Abstract

Efficient code writing is both a critical and challenging task, especially with the growing demand for computationally intensive algorithms in statistical and machine-learning applications. Despite the availability of significant computational power today, the need for optimized algorithm implementations remains crucial. Many R users rely on Rcpp to write performant code in C++, but writing and benchmarking C++ code presents its own difficulties. While R's benchmarking tools are insufficient for measuring the execution times of C++ code segments, C++'s native profiling tools often come with a steep learning curve. The rcpptimer package bridges this gap by offering a simple and efficient solution for timing C++ code within the Rcpp ecosystem. This novel package introduces a user-friendly tic-toc class that supports overlapping and nested timers and OpenMP parallelism, providing nanosecond-level time resolution. Results, including summary statistics, are seamlessly passed back to R without requiring users to write any C++ code. This paper contextualizes the rcpptimer package within the broader ecosystem of R and C++ profiling tools, explains the motivation behind its development, and offers a comprehensive overview of its implementation. Supplementary to this paper, we provide multiple vignettes that thoroughly explain this package's usage.

rcpptimer: Rcpp Tic-Toc Timer with OpenMP Support

TL;DR

rcpptimer addresses the need to benchmark and profile C++ code executed from R, especially in parallel OpenMP contexts. It introduces a tic-toc timer with support for overlapping and nested timers, automatic return of aggregated results to R, and nanosecond-level resolution. Key contributions include thread-aware timing using per-thread keys, online aggregation via the Welford algorithm, and a destructor-backed automatic stop/return behavior, all within an accessible Rcpp workflow. The tool simplifies profiling of Rcpp code, supports package integration, and is backed by vignettes, tests, and continuous integration for cross-platform reliability.

Abstract

Efficient code writing is both a critical and challenging task, especially with the growing demand for computationally intensive algorithms in statistical and machine-learning applications. Despite the availability of significant computational power today, the need for optimized algorithm implementations remains crucial. Many R users rely on Rcpp to write performant code in C++, but writing and benchmarking C++ code presents its own difficulties. While R's benchmarking tools are insufficient for measuring the execution times of C++ code segments, C++'s native profiling tools often come with a steep learning curve. The rcpptimer package bridges this gap by offering a simple and efficient solution for timing C++ code within the Rcpp ecosystem. This novel package introduces a user-friendly tic-toc class that supports overlapping and nested timers and OpenMP parallelism, providing nanosecond-level time resolution. Results, including summary statistics, are seamlessly passed back to R without requiring users to write any C++ code. This paper contextualizes the rcpptimer package within the broader ecosystem of R and C++ profiling tools, explains the motivation behind its development, and offers a comprehensive overview of its implementation. Supplementary to this paper, we provide multiple vignettes that thoroughly explain this package's usage.
Paper Structure (17 sections)