aprof

Amdahl's profiler, directed optimization.

https://github.com/marcodvisser/aprof

Science Score: 33.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: plos.org
  • Committers with academic emails
    1 of 3 committers (33.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (14.5%) to scientific vocabulary
Last synced: 10 months ago · JSON representation

Repository

Amdahl's profiler, directed optimization.

Basic Info
  • Host: GitHub
  • Owner: MarcoDVisser
  • Language: R
  • Default Branch: master
  • Size: 1.9 MB
Statistics
  • Stars: 21
  • Watchers: 6
  • Forks: 2
  • Open Issues: 0
  • Releases: 0
Created about 13 years ago · Last pushed over 1 year ago
Metadata Files
Readme

README.md

aprof (0.4.1) Release notes.

cran version rstudio mirror downloads rstudio mirror downloads

Amdahl's profiler, directed optimization. Assists the evaluation of whether and where to focus code optimization, using Amdahl's law and visual aids based on line profiling. Amdahl's profiler organises profiling output files, including memory profiling, in a visually appealing way. It is meant to help to balance development vs. execution time by helping to identify the most promising sections of code to optimize and projecting potential gains. The package is an addition to R's standard profiling tools and is not a wrapper for them.

Quicklinks

Quick start and tutorials

A "10 minute" quickstart guide is supplied on the aprof github-pages site here. Detailed tutorials on aprof usage are supplied in this PLOS Computational Biology paper on efficient programming in R. Text S1 supplies a step-by step guide for R users of any level.

Installation

There is a release on CRAN, but to install a more recent developmental version from github you can download the most recent version as zip or tar ball. To install decompress these and run R CMD INSTALL on the contents of the archives, or use the devtools package to install the current development version from R.

```r

devtools is required

require(devtools) install_github("MarcoDVisser/aprof") ```

Dependencies

aprof is meant to be light and has no other dependencies other than the base R installation.

Examples

The code below defines a simple function "foo" that illustrates the inefficiency of growing data. We then run R's profiler to time the execution of the function and its various components, aprof is then used to analyse the profiling data (see below under "Examples of output").

```r require(aprof)

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(5e4)
 Rprof(append=FALSE)

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

```

Examples of output

The standard aprof plot. It shows the execution density for each line in a source code file.

r # From above example: # Create a aprof object fooaprof<-aprof("foo.R",tmp) profileplot(fooaprof)

A profile plot, which can be used for large source files. It uses the profiler samples to attempt to reconstruct the progression through the program lines. The left panel shows the progression through time, while the largest bottleneck is indicated in red. The right panel gives the density of the line calls.

Printing any aprof object will return basic information: r fooaprof

``` Source file: foo.R (9 lines).

Call Density and Execution time per line number:

  Line  Call Density  Time Density (s)

[1,] 7 282 5.64
[2,] 6 4 0.08

Totals: Calls 287 Time (s) 5.76 (interval = 0.02 (s)) ```

Using "summary" gives projections of potential code optimization gains. A table is returned with the theoretical maximal improvement in execution time for the entire profiled program when a given line of code is sped-up. See ?summary.aprof for more details.

r summary(fooaprof) ```

Largest attainable speed-up factor for the entire program

    when 1 line is sped-up with factor (S): 

 Speed up factor (S) of a line 
        1      2      4      8      16     S -> Inf**

Line: 7 : 1.00 1.96 3.76 6.98 12.19 48.00
Line
: 6 : 1.00 1.01 1.01 1.01 1.01 1.01

Lowest attainable execution time for the entire program when

         lines are sped-up with factor (S):

 Speed up factor (S) of a line  
        1      2      4      8      16   

All lines 5.760 2.880 1.440 0.720 0.360 Line: 7 : 5.760 2.940 1.530 0.825 0.472 Line: 6 : 5.760 5.720 5.700 5.690 5.685

Total sampling time:  5.76  seconds
  • Expected improvement at current scaling ** Asymtotic max. improvement at current scaling ``` One useful feature is the "targetedSummary" function. This will give a detailed summary of the time taken by each function in a given line. In the example, a call to "c" ("combine" function) in line 7, takes most time. When the option "findParent" is set to "TRUE", aprof will attempt to detect any parent functions (functions nested within other functions) and report the parent and child functions. In this case the function c is only nested within the code in L7 (line 7), and has no further parent calls.

r targetedSummary(fooaprof,target=7,findParent=TRUE)

Function Parent Calls Time c L7 168 3.36

Memory statisics

Using the previous function foo (made above), we can set "memory.profiling=TRUE", and obtain some basic memory profiling statistics. Statistics are summarized in Megabytes and included all operations (allocations and releases).

```r # Profile the function Rprof(tmp,line.profiling=TRUE,memory.profiling=TRUE) foo(5e4) Rprof(append=FALSE)

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

```

Printing a aprof object will now include basic memory usage: r fooaprof

``` Source file: foo.R (9 lines).

Call Density and Execution time per line number:

  Line  Call Density  Time Density (s)

[1,] 7 282 5.64
[2,] 6 4 0.08

Totals: Calls 287 Time (s) 5.76 (interval = 0.02 (s))

Memory statistics time per line number:

  Line   MB   

[1,] 6 0.259 [2,] 7 2.951

Total MBs (allocated and released). ```

to do list

Fix memprofiler bug Make a pretty line extraction tool as suggested by "readLines("foursail.R")[38]"

Thanks

Special thanks to Tyler Rinker, Dason Kurkiewicz, Caspar Hallmann, Angel Rubio, Mark Miller and Diego Mayer-Cantu for comments, bugreports, commits and additions to this package. Sean M. McMahon, Cory Merow, Philip Dixon, Sydne Record and Eelke Jongejans thanks for all the suggestions, comments and testing while I was developing this package.

Owner

  • Name: Marco D Visser
  • Login: MarcoDVisser
  • Kind: user
  • Location: Leiden, the Netherlands
  • Company: Leiden University

GitHub Events

Total
  • Push event: 1
Last Year
  • Push event: 1

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 162
  • Total Committers: 3
  • Avg Commits per committer: 54.0
  • Development Distribution Score (DDS): 0.012
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Marco Visser m****r@g****m 160
Dason Kurkiewicz d****k@i****u 1
diego- d****o@m****m 1
Committer Domains (Top 20 + Academic)

Packages

  • Total packages: 1
  • Total downloads:
    • cran 352 last-month
  • Total docker downloads: 43,390
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 9
  • Total maintainers: 1
cran.r-project.org: aprof

Amdahl's Profiler, Directed Optimization Made Easy

  • Versions: 9
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 352 Last month
  • Docker Downloads: 43,390
Rankings
Stargazers count: 12.2%
Forks count: 17.8%
Average: 25.6%
Dependent packages count: 29.8%
Downloads: 32.7%
Dependent repos count: 35.5%
Maintainers (1)
Last synced: 10 months ago

Dependencies

DESCRIPTION cran
  • grDevices * imports
  • graphics * imports
  • stats * imports
  • testthat * imports