JIT note
JIT Compilation in R
Just-in-time
- http://www.drewdimmery.com/jit-compilation-in-r/
- http://www.r-statistics.com/2012/04/speed-up-your-r-code-using-a-just-in-time-jit-compiler/
- http://stat.ethz.ch/R-manual/R-devel/library/compiler/html/compile.html
In ~/.Renviron
:
R_COMPILE_PKGS=TRUE
R_ENABLE_JIT=3
restart to take effect
JIT is disabled if the argument is 0. If enable is 1 then closures are compiled before their first use. If enable is 2, then in addition closures are also compiled before they are duplicated (useful for some packages, like lattice, that store closures in lists). If enable is 3 then in addition all loops are compiled before they are executed.
Usage
at the beginning of the code
require(compiler)
enableJIT(3)
fc = cmpfun(f)
system.time(fc)
The following code by Tal Galili can help to check if the function is compiled:
is.compile <- function(func)
{
# this function lets us know if a function has been byte-coded or not
#If you have a better idea for how to do this - please let me know...
if(class(func) != "function") stop("You need to enter a function")
last_2_lines <- tail(capture.output(func),2)
any(grepl("bytecode:", last_2_lines)) # returns TRUE if it finds the text "bytecode:" in any of the last two lines of the function's print
}
Published
31 July 2013
Modified
liuminzhao 07/31/2013 21:22:10