[Rd] Slow down using the compiler

Colin Gillespie csgillespie at gmail.com
Fri Oct 27 15:22:24 CEST 2017


Dear All,

In R 3.4.2 (Linux), the compiler seems to have regressed:

$ R --vanilla
g = function() {
  N = 1e7; ans = numeric(N)
  system.time({for (j in 1:N) ans[j] = 1})
}
g()
#   user  system elapsed
 # 4.272   0.000   4.272

g1 = compiler::cmpfun(g)
g1()
#   user  system elapsed
# 4.232   0.004   4.235

Running the above code in Windows 3.3.1, g() takes the same time, but g1()
takes around 0.5 seconds.

Removing the function wrapper we have

N = 1e7; ans = numeric(N)
system.time({for (j in 1:N) ans[j] = 1})
#   user  system elapsed
 # 0.304   0.000   0.304
compiler::enableJIT(0)
#[1] 3
N = 1e7; ans = numeric(N)
system.time({for (j in 1:N) ans[j] = 1})
#   user  system elapsed
 # 5.448   0.000   5.446

Best wishes

Colin

------------------

> sessionInfo()
R version 3.4.2 (2017-09-28)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.3 LTS

Matrix products: default
BLAS: /usr/lib/atlas-base/atlas/libblas.so.3.0
LAPACK: /usr/lib/atlas-base/atlas/liblapack.so.3.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8
 [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.4.2

	[[alternative HTML version deleted]]



More information about the R-devel mailing list