Home
Reading
Searching
Subscribe
Sponsors
Statistics
Posting
Contact
Spam
Lists
Links
About
Hosting
Filtering
Features Download
Marketing
Archives
FAQ
Blog
 
Gmane
From: Romain Francois <romain-5F2htOKpZ0Uq+cvokbE/HgC/G2K4zDHf <at> public.gmane.org>
Subject: Rcpp internal benchmark tool
Newsgroups: gmane.comp.lang.r.rcpp
Date: Saturday 8th December 2012 14:44:15 UTC (over 5 years ago)
Hello,

I've been using the microbenchmark package extensively and took 
inspiration from it to implement a Timer class in Rcpp to measure 
performance at a lower level.

The class is pretty raw right now. platform specific details are 
abstracted out. So the only things needed are:

- include the Timer.h header, which is **not** automatically added in 
Rcpp.h:

     #include 

- create a Timer object :

     Benchmark::Timer timer ;

- call "step" to record each step, measuring the time from the previous 
step to now.

     timer.step( "something" ) ;



Here is a full example measuring a few things:

#include 
#include 

using namespace Rcpp ;

// [[Rcpp::export]]
SEXP measure(){
     int n = 1000000 ;

     // start the timer
     Benchmark::Timer timer ;
     for( int i=0; i measure()
                   get/put get/put + rnorm(10, 0,1) 
empty loop
               2086.945600               5067.034550 
0.000622

Those numbers are numbers of nanoseconds per iteration of each loop


as I said the class is pretty raw, so if people have ideas to improve it.
See the header: 
https://r-forge.r-project.org/scm/viewvc.php/pkg/Rcpp/inst/include/Rcpp/Benchmark/Timer.h?view=markup&root=rcpp

and the implementation: 
https://r-forge.r-project.org/scm/viewvc.php/pkg/Rcpp/src/Timer.cpp?view=markup&root=rcpp

Romain


-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30

R Graph Gallery: http://gallery.r-enthusiasts.com

blog:            http://romainfrancois.blog.free.fr
|- http://bit.ly/RE6sYH : OOP with Rcpp
modules
`- http://bit.ly/Thw7IK : Rcpp modules more
flexible
 
CD: 3ms