Is it possible to improve these times?
Are they expected?
How could I activate something with the help of R to improve performance?
sessionInfo()
version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
Random number generation:
RNG: Mersenne-Twister
Normal: Inversion
Sample: Rounding
Processor: AMD Ryzen 7 1800 nEight-Core Processor 3.90 GHz
Installed RAM 16.0 GB
library(data.table)
library(microbenchmark)
nrow=1e7
ncol = 10
ColList <-c("L1","L2")
set.seed(42)
ss<-as.data.table(replicate(2,rexp(nrow)))
print(ss,topn = 3)
ColList
#ta<-replicate(length(ColList),rexp(nrow))
ttDT=microbenchmark(
ta<-replicate(length(ColList),rexp(nrow)),
DT1=ss[,(ColList) := {as.list(as.data.table(ta))}],
DT2=ss[,(ColList) := {as.list(as.data.table(replicate(length(ColList),rexp(nrow))))}],
DT3=ss[,(ColList) := {as.data.table(replicate(length(ColList),rexp(nrow)))}],
DT4=ss[,(ColList) := {as.data.table(replicate(length(ColList),rexp(.N)))}],
##https://community.rstudio.com/u/nwerth
DT5=ss[, (ColList) := replicate(length(ColList), rexp(.N), simplify = FALSE)],
#mapply(function(x,y){rep(rexp(x),y,len = 3)},c(3),c(1,1))
DT6=ss[,(ColList) := {as.data.table(mapply(function(x,y){rep(rexp(x),y,len = .N)},c(.N),c(1,1)))}],
DT7=ss[,(ColList) := {as.data.table(mapply(function(x,y){rep(rexp(x),y,len = .N)},c(.N),c(rep(1,length(ColList)))))}]
)
ttDT
ttDT
Unit: milliseconds
expr min lq mean median uq max neval
ta <- replicate(length(ColList), rexp(nrow)) 753.2457 782.72410 877.8430 930.9511 940.1743 956.8393 100
DT1 82.6479 83.94285 172.8322 134.5889 283.2170 308.3972 100
DT2 844.7064 993.69225 989.1314 1007.4347 1014.7164 1092.7617 100
DT3 844.5222 900.12560 975.4255 1006.7963 1011.3696 1085.1980 100
DT4 844.3975 959.01670 981.6247 1008.3374 1015.3442 1079.5024 100
DT5 662.6736 687.03540 764.6300 714.5847 858.8434 883.7546 100
DT6 892.9834 1029.61100 1043.5304 1070.9019 1098.1291 1132.0790 100
DT7 893.1555 942.93830 1036.4575 1059.7355 1089.2190 1144.0754 100
library(ggplot2)
autoplot(ttDT)