Rprof has tools for profiling memory:
siml <- function(l) { c <- rep(0,l); hits <- 0 #variables initialization listp <- as.list(seq(10000000)) pow2 <- function(x) { x2 <- sqrt( x[1]*x[1]+x[2]*x[2] ); return(x2) } for(i in 1:l){ x = runif(2,-1,1) if( pow2(x) <=1 ){ hits <- hits + 1 } dens <- hits/i; pi_partial = dens*4; c[i] = pi_partial }; return(c) }