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