From SO:
https://stackoverflow.com/questions/62019120/why-does-data-table-notation-for-column-retrieval-affect-speed/62028864#62028864
x <- as.data.table(as.character(rnorm(20000000,1,0.5)))
setkey(x,V1)
tic(); x[,.(V1)]; toc()
# 25.08 sec elapsed
(timing is even worse on my machine)
The bottleneck appears to be this line:
|
if (haskey(x) && all(key(x) %chin% names(jval)) && suppressWarnings(is.sorted(jval, by=key(x)))) # TO DO: perhaps this usage of is.sorted should be allowed internally then (tidy up and make efficient) |
IINM we can tell the output is sorted because V1 is the key and it appears as a name -- no need to compute the sort order all over again.
Reactions are currently unavailable
From SO:
https://stackoverflow.com/questions/62019120/why-does-data-table-notation-for-column-retrieval-affect-speed/62028864#62028864
(timing is even worse on my machine)
The bottleneck appears to be this line:
data.table/R/data.table.R
Line 1339 in dd7609e
IINM we can tell the output is sorted because V1 is the key and it appears as a name -- no need to compute the sort order all over again.