Skip to content

transform is ~100x slower on data.table than on data.frame #5492

@OfekShilon

Description

@OfekShilon

# Minimal reproducible example

> df <- data.frame(x = runif(n = 1e7))
> dt <- as.data.table(df)
> system.time(df <- transform(df, y = round(x)))
   user  system elapsed 
  0.122   0.031   0.152 
> system.time(dt <- transform(dt, y = round(x)))
   user  system elapsed 
 19.658   0.157  19.808 

# Output of sessionInfo()
Observed on multiple configurations, the particular one I'm reporting from is with data.table from github trunk:

R version 3.6.3 (2020-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

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

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

other attached packages:
[1] data.table_1.14.5

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions