What is the optimization level for compiling your C++ code? It matters. Jiqiang
On Mon, Aug 27, 2012 at 5:08 PM, Peng Yu <pengyu...@gmail.com> wrote: > On Mon, Aug 27, 2012 at 3:44 PM, Dirk Eddelbuettel <e...@debian.org> wrote: > > > > On 27 August 2012 at 15:17, Peng Yu wrote: > > | Hi Dirk, > > | > > | > inlines uses .Call, so there is a slight logical problem here... > And yes, > > | > > | What is the logical problem? > > > > What inline's cxxfunction() gives you is an object which uses .Call. So > it > > is a little hard to imagine how that could be faster than using .Call as > it > > I agree with you that it is hard to imagine. > > > also uses .Call. More likely, it may reflect random fluctuations in your > > setup as also suggested by Doug. > > Why don't you try it on your system and see what number you get? I > have tried on two systems Mac and linux, if it were due to > flucturation, one can not be consistently faster than the other. > > microbench run the function 100 times by default. it does not seem > that Doug's comment makes sense. > > In the following, I try to run 1000 times with both microbenchmark as > well as benchmark. "benchmark" shows that calling the wrapper function > is a little slower, but "microbenchmark" still shows the opposite. > Given our belief that the wrapper should be slower, I tend to think > that there might be some bug in the way microbenchmark record the run > time. But I'm not completely sure. > > Both evaluation methods still show inline is the fastest (this is true > on linux, except the difference is only 2 times not almost 10 times). > > > # on mac > > library(microbenchmark) > > microbenchmark(test(xx), test_inline(xx), .Call('test', xx), times=1000) > Unit: microseconds > expr min lq median uq max > 1 .Call("test", xx) 94.515 95.6160 96.3790 97.7700 135.709 > 2 test_inline(xx) 4.451 5.1655 6.4150 6.6380 29.944 > 3 test(xx) 69.004 69.8880 70.5375 71.4975 199.150 > > library(rbenchmark) > > benchmark(test(xx), test_inline(xx), .Call('test', xx), > replications=1000) > test replications elapsed relative user.self sys.self > user.child sys.child > 3 .Call("test", xx) 1000 0.076 8.444444 0.044 0.032 > 0 0 > 2 test_inline(xx) 1000 0.009 1.000000 0.009 0.000 > 0 0 > 1 test(xx) 1000 0.078 8.666667 0.046 0.032 > 0 0 > > > -- > Regards, > Peng > _______________________________________________ > Rcpp-devel mailing list > Rcpp-devel@lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel >
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel