vignettes/R-Profiling-code.Rmd
R-Profiling-code.Rmd
AFTER that, then you can use 2 great tools:
profvis
package (built into the latest Rstudio previews, but not the official release version)microbenchmark
packagemicrobenchmark::microbenchmark(
loop = {
a <- vector()
for (i in 1:1000) a[i] <- runif(1)
},
vectorized = { a <- runif(1000) }
)
## Unit: microseconds
## expr min lq mean median uq max
## loop 4277.067 4794.5435 6004.2868 5559.541 6955.0720 12148.464
## vectorized 32.553 35.1925 40.0816 36.659 39.8855 59.535
## neval
## 100
## 100
If you have Rstudio version >=0.99.1208
, then it has profiling as a menu item.
alternatively, we wrap any block of code with profvis
This can be a spades()
call, so it will show you the entire model:
profvis::profvis({a <- rnorm(10000000)})
spades
callTry it:
mySim <- simInit(
times = list(start = 0.0, end = 2.0, timeunit = "year"),
params = list(
.globals = list(stackName = "landscape", burnStats = "nPixelsBurned")
),
modules = list("randomLandscapes", "fireSpread", "caribouMovement"),
paths = list(modulePath = system.file("sampleModules", package = "SpaDES"))
)
profvis::profvis({spades(mySim)})
If you have used these tools, then: