Using Rperform with popular R packages to analyze their performance

Rperform is a first-of-its-kind package for detailed performance analysis of R packages. In general, Rperform aims to be a standard tool for performance testing R packages and their code.

Rperform can be used to plot the performance metrics of a R package.  In this post, I have explained how to use Rperform with different R packages, so that we can plot the performance of their code in the form of certain performance metrics by giving testfiles for specified number of commits.

  • First of all, get to know about your current working path. In R, use getwd(), to know about the current path.
  • Set the path to the respective directory of R package, which we want to test the performance metrics for. In R, use function setwd(“/path/to/testfile”) to set the desired path.

The main performance parameters involve time, memory, and testmetrics. “plot_metric()” is the most basic function to do so. we can plot the particular metrics using the following code. Now, we can analyze the performance of the code in a single branch and between different branches also.

Plotting performance metrics on a single branch:

setwd(/path/to/Rpackage)
library(Rperform)
plot_metrics(test_path = "tests/testthat/abc.r", metric = "time", num_commits = 5, save_data = T, save_plots = T)

The explanation for the above code is given as below:

  • Include the Rperform library.
  • Set the “metric” parameter to the particular metric(eg. time, memory or memtime)
  • Specify the number of commits.
  • Set the save_data and save_plot to T, if you want to save the results or in other case to F.

Given below is the link to the demo repository which comprises the results of analysis done with various R packages using Rperform.

https://github.com/DevinderKaur/RpeformDEMO

The popular packages being used for testing purposes are:

  • knitr: A general-purpose package for dynamic report generation in R.
  • stringr: A simple, consistent wrappers for common string operations.
  • ggplot2: The ggplot2 package, created by Hadley Wickham, offers a powerful graphics language for creating elegant and complex plots. Its popularity in the R community has exploded in recent years.
  • git2r: Provides access to ‘Git’ repositories to extract data and running some basic ‘Git’ commands.
  • dplyr: A fast, consistent tool for working with data frame like objects, both in memory and out of memory.

 

 

Leave a comment