From ggrothendieck at gmail.com  Thu Oct 31 00:14:18 2013
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed, 30 Oct 2013 19:14:18 -0400
Subject: [Rd] Huge performance difference between implicit and explicit
	print
In-Reply-To: <CABdHhvEkfACu91SD5p01kgJJiqNUwtQK-fnbgmFOYqFo9ScS9Q@mail.gmail.com>
References: <CABdHhvEkfACu91SD5p01kgJJiqNUwtQK-fnbgmFOYqFo9ScS9Q@mail.gmail.com>
Message-ID: <CAP01uRnOqOuknCNsnCopuy5Kxj3-JJG656C_e59m8fXo4kKc5w@mail.gmail.com>

On Wed, Oct 30, 2013 at 6:22 PM, Hadley Wickham <h.wickham at gmail.com> wrote:
> 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

If I change print(df) to print.data.frame(df) it hangs.

R version 3.0.2 Patched (2013-10-06 r64031) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)



[Rd] Huge performance difference between implicit and explicit print
Gabor Grothendieck