-
Notifications
You must be signed in to change notification settings - Fork 9
Tutorial: Using Rperform with packages
-
Clone the forked repository on to on your local machine.
-
Install the Rperform package.
-
You will also need to install the testthat package for following this tutorial.
-
Look at timeCheck.R in R/ and testTime.R in tests/testthat
-
timeCheck.R contains function definitions for
justTimeIt()
andjustTimeIt2()
. Each of these functions contains a line whereSys.sleep(time = *number of seconds to pause*)
is being called. This is the key portion of the code since the number being passed into Sys.sleep() differs across the 8 commits. -
testTime.R contains 2 trivial testthat code blocks. Each of these simply make sure that justTimeIt() and justTimeIt2() are returning the correct values when called. However, our concern is not the correctness of the code but the runtime performance. The real purpose of these code blocks is simply calling the two functions.
-
Make sure that you are in the home directory of the package, i.e. RperformTestPackage/
-
Load Rperform and then call the function
plot_metrics()
as shown below:
library("Rperform")
plot_metrics(test_path = "tests/testthat/testTime.R", metric = "time", num_commits = 8)
The below plot should get generated:
-
What
plot_metrics()
did was run the contents of the file across the last 8 commits. It did so by taking a snapshot of the file from the most recent version and running it after checking out to each previous version one by one. While running these, it measured the runtime values and subsequently, plotted them. -
When run on a file containing testthat code blocks, it measures the performance metrics for each block as well in addition to the file itself. This is what we can see on the plot.
-
If you wanted to work directly with the runtime performance data, you can obtain it as follows:
time_compare(test_path = "tests/testthat/testTime.R", num_commits = 8)