Richard Cotton
2011-Dec-19 10:34 UTC
[Rd] Speed issue when writing to RGui console from tcl/tk GUI
It seems that there are speed issues when printing to the R console from a tcl/tk GUI. Here are functions to write a lot of output, and to display how long it takes. printsalot <- function(n) { for(i in 1:n) cat(i, fill = TRUE) } timings <- function(n = 1e3) { print(system.time(printsalot(n))) } Calling timings() from the console reveals a run time of a few hundredths of a second. The following GUI has two buttons. Clicking the "slow" buttons just calls timings directly, and takes several seconds to run. However, if we request input from the console, via readline (the "fast" button) then the timing drops back down to hundredths of a second. library(tcltk) win <- tktoplevel() btn1 <- ttkbutton(win, text = "slow", command = function() timings()) btn2 <- ttkbutton(win, text = "fast", command = function() {readline("Press ENTER > "); timings()}) tkpack(btn1, btn2) I've only observed this slow behaviour with RGui on Windows (XP) - it doesn't happen with Rterminal or eclipse/StatET or RStudio. I want a few people to run this code to see if it affects, for example, other OSes, to narrow down the extent of the problem before I submit it as a bug. Also, if you have any insight as to what is happening or fixes, I'd be interested to know. Regards, Richie. [[alternative HTML version deleted]]
peter dalgaard
2011-Dec-20 12:54 UTC
[Rd] Speed issue when writing to RGui console from tcl/tk GUI
On Dec 19, 2011, at 11:34 , Richard Cotton wrote:> It seems that there are speed issues when printing to the R console from a > tcl/tk GUI. > > Here are functions to write a lot of output, and to display how long it > takes. > > printsalot <- function(n) > { > for(i in 1:n) cat(i, fill = TRUE) > } > > timings <- function(n = 1e3) > { > print(system.time(printsalot(n))) > } > > Calling timings() from the console reveals a run time of a few hundredths > of a second. > > The following GUI has two buttons. Clicking the "slow" buttons just calls > timings directly, and takes several seconds to run. However, if we request > input from the console, via readline (the "fast" button) then the timing > drops back down to hundredths of a second. > > library(tcltk) > win <- tktoplevel() > btn1 <- ttkbutton(win, text = "slow", command = function() timings()) > btn2 <- ttkbutton(win, text = "fast", command = function() {readline("Press > ENTER > "); timings()}) > tkpack(btn1, btn2) > > I've only observed this slow behaviour with RGui on Windows (XP) - it > doesn't happen with Rterminal or eclipse/StatET or RStudio. > > I want a few people to run this code to see if it affects, for example, > other OSes, to narrow down the extent of the problem before I submit it as > a bug. >Nothing of the sort is happening on OSX. The RGui console is known to be slow if unbuffered, so you may want to experiment with turning buffering on. It could also be some event handling issue, but it doesn't really seem likely to me. -pd> Also, if you have any insight as to what is happening or fixes, I'd be > interested to know. > > Regards, > Richie. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com