A wrapper around Google's perftools profiler and pprof visualizer.
library(gprofiler)
profile(my_expensive_function(100000)) # On completion, shows results in a web browser.
Results are only meaningful if my_expensive_function(100000)
takes longer than around 30 seconds.
The gprofiler::profile()
function profiles only C++ code.
To profile R code, use the profviz package instead.
Ubuntu Linux
sudo apt-get install libgoogle-perftools-dev
sudo apt-get install golang-go # In case you don't have go installed.
export GOPATH=$HOME/go # Add this to your .bash_profile.
export PATH=$PATH:$GOPATH/bin # Add this to your .bash_profile.
go get github.com/google/pprof
OS X
brew install google-perftools
brew install binutils # For gobjdump.
sudo ln -s /usr/local/bin/gobjdump /usr/local/bin/objdump # Needed by pprof.
brew install go --cross-compile-common # In case you don't have go installed.
export GOPATH=$HOME/go # Add this to your .bash_profile.
export PATH=$PATH:$GOPATH/bin # Add this to your .bash_profile.
go get github.com/google/pprof
sudo mv /usr/local/bin/pprof /usr/local/bin/pprof.pl # Ignore the older pprof.
library(devtools)
devtools::install_github('nimble-dev/gprofiler')