[Rcpp-devel] Why inline function is much faster than .Call?

Peng Yu pengyu.ut at gmail.com
Mon Aug 27 22:17:34 CEST 2012


Hi Dirk,

> inlines uses .Call, so there is a slight logical problem here...  And yes,

What is the logical problem?

> functions have overheads.

If that is the case, .Call("test", xx) should be faster than test(xx).
But it is not (see below). This looks wired to me.

>
> | library(microbenchmark)
> | microbenchmark(test(xx))
> | microbenchmark(test_inline(xx))
> | microbenchmark(.Call('test', xx))
>
> The normal idiom is a _single_ call so that you can compare:
>
>   microbenchmark(test(xx), test_inline(xx), .Call('test', xx))

Here is the output.

> microbenchmark(test(xx), test_inline(xx), .Call('test', xx))
Unit: microseconds
               expr                      min                       lq
                 median                       uq
max
1 .Call("test", xx) 94.831999999999993633537 96.090499999999991587174
97.557000000000002160050 99.762499999999988631316
128.83099999999998885869
2   test_inline(xx)  4.440000000000000390799  5.101499999999999701572
6.393000000000000682121  6.615000000000000213163
30.33899999999999863576
3          test(xx) 69.683000000000006934897 70.387500000000002842171
71.593500000000005911716 73.153500000000008185452
198.30899999999999749889

-- 
Regards,
Peng


More information about the Rcpp-devel mailing list