From h.wickham at gmail.com  Wed Oct 30 23:22:40 2013
From: h.wickham at gmail.com (Hadley Wickham)
Date: Wed, 30 Oct 2013 17:22:40 -0500
Subject: [Rd] Huge performance difference between implicit and explicit print
Message-ID: <CABdHhvEkfACu91SD5p01kgJJiqNUwtQK-fnbgmFOYqFo9ScS9Q@mail.gmail.com>

Hi all,

Can anyone help me understand why an implicit print (i.e. just typing
df at the console), is so much slower than an explicit print (i.e.
print(df)) in the example below?  I see the difference in both Rstudio
and in a terminal.

# Construct large df as quickly as possible
dummy <- 1:18e6
df <- lapply(1:10, function(x) dummy)
names(df) <- letters[1:10]
class(df) <- c("myobj", "data.frame")
attr(df, "row.names") <- .set_row_names(18e6)

print.myobj <- function(x, ...) {
  print.data.frame(head(x, 2))
}

start <- proc.time(); df; flush.console(); proc.time() - start
#  user  system elapsed
# 0.408   0.557   0.965
start <- proc.time(); print(df); flush.console(); proc.time() - start
#  user  system elapsed
# 0.019   0.002   0.020

sessionInfo()
# R version 3.0.2 (2013-09-25)
# Platform: x86_64-apple-darwin10.8.0 (64-bit)
#
# locale:
# [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#
# attached base packages:
# [1] stats     graphics  grDevices utils     datasets  methods   base

Thanks!

Hadley

-- 
Chief Scientist, RStudio
http://had.co.nz/



[Rd] Huge performance difference between implicit and explicit print
Hadley Wickham