I am comparing two different algorithms in terms of speed and memory usage. I can calculate the processing time with proc.time() as follows but am not sure how to calculate the memory usage. ptm <- proc.time() x <- rnorm(1000000) proc.time() - ptm I would like to be within R itself since I will test the algorithm several hundred times and in batch mode. So manually looking up 'top' may not be feasible. help.seach("memory") suggests memory.profile and gc but I am not sure how to use these. Sorry if this is a basic question. Thank you. Regards, Adai
On Mon, 13 Sep 2004, Adaikalavan Ramasamy wrote:> I am comparing two different algorithms in terms of speed and memory > usage. I can calculate the processing time with proc.time() as follows > but am not sure how to calculate the memory usage. > > ptm <- proc.time() > x <- rnorm(1000000) > proc.time() - ptmHmm ... see ?system.time!> I would like to be within R itself since I will test the algorithm > several hundred times and in batch mode. So manually looking up 'top' > may not be feasible. help.seach("memory") suggests memory.profile and gc > but I am not sure how to use these.I don't think you can. You can find out how much memory R is using NOW, but not the peak memory usage during a calculation. Nor is that particularly relevant, as it depends on what was gone on before, the word length of the platform and the garbage collection settings. On Windows, starting in a clean session, calling gc() and memory.size(), then calling your code and memory.size(max=TRUE) will give you a fair idea, but `top' indicates some Unix-alike. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
If you only have simple objects in your function, you might be able to use a function like totalMem <- function() { sum(sapply(ls(all = TRUE), function(x) object.size(get(x)))) / 2^20 } which should give you a rough idea of the memory usage (in MB) in the current environment. -roger Adaikalavan Ramasamy wrote:> I am comparing two different algorithms in terms of speed and memory > usage. I can calculate the processing time with proc.time() as follows > but am not sure how to calculate the memory usage. > > ptm <- proc.time() > x <- rnorm(1000000) > proc.time() - ptm > > I would like to be within R itself since I will test the algorithm > several hundred times and in batch mode. So manually looking up 'top' > may not be feasible. help.seach("memory") suggests memory.profile and gc > but I am not sure how to use these. > > Sorry if this is a basic question. Thank you. > > Regards, Adai > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >