Skip to content

Latest commit

 

History

History
62 lines (44 loc) · 3.36 KB

File metadata and controls

62 lines (44 loc) · 3.36 KB
title Improve performance by using R code profiling function
description Collect useful information to improve performance and get faster results on R computations on SQL Server by using R profiling functions.
author VanMSFT
ms.author vanto
ms.date 08/24/2023
ms.service sql
ms.subservice machine-learning-services
ms.topic how-to
monikerRange >=sql-server-2016||>=sql-server-linux-ver15

Use R code profiling functions to improve performance

[!INCLUDE SQL Server 2016 and later]

This article describes performance tools provided by R packages to get information about internal function calls. You can use this information to improve the performance of your code.

Tip

This article provides basic resources to get you started. For expert guidance, we recommend the Performance section in "Advanced R" by Hadley Wickham.

Use RPROF

rprof is a function included in the base package utils, which is loaded by default.

In general, the rprof function works by writing out the call stack to a file, at specified intervals. You can then use the summaryRprof function to process the output file. One advantage of rprof is that it performs sampling, thus lessening the performance load from monitoring.

To use R profiling in your code, you call this function and specify its parameters, including the name of the location where the log file is written. Profiling can be turned on and off in your code. The following syntax illustrates basic usage:

# Specify profiling output file.
varOutputFile <- "C:/TEMP/run001.log")
Rprof(varOutputFile)

# Turn off profiling
Rprof(NULL)
    
# Restart profiling
Rprof(append=TRUE)

Note

Using this function requires that Windows Perl be installed on the computer where code is run. Therefore, we recommend that you profile code during development in an R environment, and then deploy the debugged code to SQL Server.

R System Functions

The R language includes many base package functions for returning the contents of system variables. For example, as part of your R code, you might use Sys.timezone to get the current time zone, or Sys.Time to get the system time from R.

To get information about individual R system functions, type the function name as the argument to the R help() function from an R command prompt.

help("Sys.time")

Debug and Profiling in R

The documentation for Microsoft R Open, which is installed by default, includes a manual on developing extensions for the R language that discusses profiling and debugging in detail.

Next steps