Skip to content

Figure out why gather() is so much slower than melt() #18

Description

@hadley

Activity

  1. hadley commented on Aug 22, 2014

    @hadley
    MemberAuthor

    Looks like it's the non-standard eval:

    library(microbenchmark)
    iris1 <- iris[sample(1:nrow(iris), 1e4, replace = T), ] 
    
    microbenchmark(
      melt = reshape2::melt(iris1,id.vars="Species"), 
      gather = tidyr::gather(iris1, variable, value, -Species),
      gather_ = tidyr::gather_(iris1, quote(variable), quote(value), c("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"))
    )
    Unit: milliseconds
        expr  min   lq median   uq   max neval
        melt 2.41 2.66   3.15 4.87 52.49   100
      gather 3.97 4.98   6.40 6.82  8.41   100
     gather_ 2.43 2.67   3.07 4.94 51.42   100
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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