Learn R Programming

aprof (version 0.4.1)

plot.aprof: plot.aprof

Description

Plot execution time, or total MB usage when memory profiling, per line of code from a previously profiled source file. The plot visually shows bottlenecks in a program's execution time, shown directly next to the code of the source file.

Usage

# S3 method for aprof
plot(x, y, ...)

Arguments

x

An aprof object as returned by aprof(). If this object contains both memory and time profiling information both will be plotted (as proportions of total time and total memory allocations.

y

Unused and ignored at current.

Additional printing arguments. Unused at current.

Examples

Run this code
# NOT RUN {
# create function to profile
foo <- function(N){
        preallocate<-numeric(N)
        grow<-NULL  
         for(i in 1:N){
             preallocate[i]<-N/(i+1)
             grow<-c(grow,N/(i+1))
            }
}

## save function to a source file and reload
dump("foo",file="foo.R")
source("foo.R")

## create file to save profiler output
tmp<-tempfile()

## Profile the function
Rprof(tmp,line.profiling=TRUE)
foo(1e4)
Rprof(append=FALSE)

## Create a aprof object
fooaprof<-aprof("foo.R",tmp)
plot(fooaprof)
# }

Run the code above in your browser using DataLab