Skip to content
Prev 992 / 10988 Next

[Rcpp-devel] Using sugar expressions for evaluating deviance residuals

Le 16/08/10 15:33, Douglas Bates a ?crit :
Yes. This is perturbing to me too.

One element of confusion perhaps is that inline does bring some overhead 
which we can minimize by massaging the object it creates (don't try this 
at home kids ... ):

 > fx4
An object of class "CFunc"
function (yy, ee, ww)
{
     if (!file.exists(libLFile))
         libLFile <<- compileCode(f, code, "C++", verbose)
     if (!(f %in% names(getLoadedDLLs())))
         dyn.load(libLFile)
     .Call("file4431b782", PACKAGE = f, yy, ee, ww)
}
<environment: 0x1022a3060>
...


 > fx4_ <- fx4 at .Data
 > body(fx4_) <- call( "{", body( fx4_ )[[4]] )
 >
 > fx4__ <- fx4_
 > body(fx4__)[[2]][[2]] <- as.name( "SYMBOL" )
 > assign( "SYMBOL",
+ getNativeSymbolInfo( get( "f", environment(fx4) ), getDynLib( fx4 ) ) ,
+ environment(fx4__) )
 >
 > fx4_
function (yy, ee, ww)
{
     .Call("file4431b782", PACKAGE = f, yy, ee, ww)
}
<environment: 0x1022a3060>
 > fx4__
function (yy, ee, ww)
{
     .Call(SYMBOL, PACKAGE = f, yy, ee, ww)
}
<environment: 0x1022a3060>


 > benchmark(fx0(yy,ee,ww), fx4(yy,ee,ww), fx4_(yy,ee,ww), 
fx4__(yy,ee,ww),replications = 500, columns=c("test", "replications", 
"elapsed", "user.self", "relative"))
                test replications elapsed user.self relative
1   fx0(yy, ee, ww)          500   0.956     0.913 1.000000
4 fx4__(yy, ee, ww)          500   1.165     1.130 1.218619
3  fx4_(yy, ee, ww)          500   1.186     1.152 1.240586
2   fx4(yy, ee, ww)          500   1.281     1.244 1.339958

It does not explain it all, but still ...
Perhaps. I don't compile R these days, as I just install the nightlies 
every now and then, so I'm not sure which optimisation is used.

For inline, verbose = TRUE will show you what it is using.