GithubHelp home page GithubHelp logo

rcppclock's Introduction

rcppclock's People

Contributors

zdebruine avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

berrij

rcppclock's Issues

Suggestion: Switch back to std::chrono::high_resolution_clock

Hi,

I figured the cause of the MacOS compilation problem that I mentioned earlier. It turns out that those 2 #defines 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

Handover to R is slow

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.