search for: doublethisint

Displaying 3 results from an estimated 3 matches for "doublethisint".

2015 Mar 02
3
R-devel does not update the C++ returned variables
...s on the size of the input vector. i + i becomes the winner for longer vectors (e.g. i <- 1:1e6), but a proper Rcpp version is still approximately twice as fast. Rcpp::cppFunction("NumericVector doubleThisNum(NumericVector x) { return(2*x); }") Rcpp::cppFunction("IntegerVector doubleThisInt(IntegerVector x) { return(2*x); }") i <- 1:1e6 mb <- microbenchmark::microbenchmark(doubleThisNum(i), doubleThisInt(i), i*2, 2*i, i*2L, 2L*i, i+i, times=100) plot(mb, log="y", notch=TRUE) > (mb <- microbenchmark(doubleThis(i), i*2, 2*i, i*2L, 2L*i, i+i, times=2^12)) &...
2015 Mar 02
0
R-devel does not update the C++ returned variables
...ithms also depends on the size > of the input vector. i + i becomes the winner for longer vectors (e.g. i > <- 1:1e6), but a proper Rcpp version is still approximately twice as fast. The difference in speed is probably due to the fact that R does safe arithmetic. C or C++ do not: > doubleThisInt(i) [1] 2147483642 2147483644 2147483646 NA -2147483646 -2147483644 > 2L * i [1] 2147483642 2147483644 2147483646 NA NA NA Warning message: In 2L * i : NAs produced by integer overflow H. > > Rcpp::cppFunction("NumericVector double...
2015 Mar 02
3
R-devel does not update the C++ returned variables
On 2 March 2015 at 09:09, Duncan Murdoch wrote: | I generally recommend that people use Rcpp, which hides a lot of the | details. It will generate your .Call calls for you, and generate the | C++ code that receives them; you just need to think about the real | problem, not the interface. It has its own learning curve, but I think | it is easier than using the low-level code that you need to