Install any skill in seconds. Free to start, no credit card required.
Get Started Free →R performance best practices covering profiling with profvis, benchmarking with bench, vctrs, and optimization strategies.
86% 100%+14 ptsof test cases passed
Passed 22 of 22 test cases with the skill, and 19 of 22 without it.
I have a complex script with multiple nested function calls taking 45 seconds, but I don't know which line or function is causing the slowdown. Should I benchmark individual helper functions right away or line-profile the entire execution block, and what tool should I use?
recommends profvis for identifying unknown bottlenecks across call stacks
3 of 3 safety checks passed
Profiling, benchmarking, and optimization strategies for R code
| Tool | Use When | Don't Use When | What It Shows |
|---|---|---|---|
profvis | Complex code, unknown bottlenecks | Simple functions, known issues | Time per line, call stack |
bench::mark() | Comparing alternatives | Single approach | Relative performance, memory |
system.time() | Quick checks | Detailed analysis | Total runtime only |
Rprof() | Base R only environments | When profvis available | Raw profiling data |
# 1. Profile first - find the actual bottlenecks
library(profvis)
profvis({
# Your slow code here
})
# 2. Focus on the slowest parts (80/20 rule)
# Don't optimize until you know where time is spent
# 3. Benchmark alternatives for hot spots
library(bench)
bench::mark(
current = current_approach(data),
vectorized = vectorized_approach(data),
parallel = map(data, in_parallel(func))
)
# 4. Consider tool trade-offs based on bottleneck type
Next to this one in the catalogue, plus more from the same author.