zdebruine / rcppclock Goto Github PK
View Code? Open in Web Editor NEWA simple tick-tock clock for benchmarking Rcpp code
A simple tick-tock clock for benchmarking Rcpp code
Hi,
I figured the cause of the MacOS compilation problem that I mentioned earlier. It turns out that those 2 #define
s were causing trouble:
#define duration(a) std::chrono::duration_cast<std::chrono::nanoseconds>(a).count()
#define now() std::chrono::steady_clock::now()
You can check out this clock.h file which compiles fine on every OS.
That said, you may want to switch back to using std::chrono::high_resolution_clock
as it may be more accurate as discussed here.
Thanks again for this awesome package
BerriJ
Hi,
let me say that I love RcppClock and I use it frequently.
However, recently I discovered performance issues and it turned out that RcppClock itself caused those issues. Considers this simple .cpp file:
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::depends(RcppProgress)]]
// [[Rcpp::depends(RcppClock)]]
// [[Rcpp::plugins("cpp11")]]
#include <RcppArmadillo.h>
#include <progress.hpp>
#include <RcppClock.h>
#include <thread>
// [[Rcpp::export]]
int test()
{
int X = 50;
int Y = 50;
int Z = 50;
Progress prog(X * Y * Z);
Rcpp::Clock clock;
arma::wall_clock timer;
for (unsigned int x = 0; x < X; x++)
{
for (unsigned int y = 0; y < Y; y++)
{
for (unsigned int z = 0; z < Z; z++)
{
clock.tick("Z action");
arma::vec tmp(100, arma::fill::randu);
clock.tock("Z action");
prog.increment();
}
}
}
timer.tic();
clock.stop("times");
double n = timer.toc();
arma::cout << "number of seconds: " << n << arma::endl;
return 0;
}
RcppArmadillo, RcppClock, and RcppProgress are needed. Then this can be easily sourced using Rcpp::sourceCpp("test.cpp")
Now consider the following R code:
[R] test()
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
number of seconds: 86.5003
[1] 0
The progressbar fills up extremely quick. However, it takes 86 seconds for clock.stop("times");
to finish. How is that?
We can see that times
's footprint is not tiny indeed:
[R] sz <- object.size(times)
[R] print(sz, units = "MB")
1.9 Mb
However, 86 Seconds seems a bit hefty even if we have 1.2MB of data which has to be processed in some way.
Thank you so much.
BerriJ
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.