Learn R Programming

Laurae (version 0.0.0.9001)

timer_func_print: Get Function Time in Milliseconds (with printing)

Description

This function returns the time needed for a function to run in milliseconds, and prints it.

Usage

timer_func_print(expr, seconds = FALSE, pre_msg = "The function ran in ",
  msg_format = "%05.03f", post_msg = ifelse(seconds == TRUE, " seconds.",
  " milliseconds."), linebreak = TRUE)

Arguments

expr
Type: any expression. An expression to evalutate (the expression you want to benchmark).
seconds
Type: logical. Whether you want milliseconds (default) or seconds. Defaults to FALSE.
pre_msg
Type: character. The message preceeding the time print. Defaults to "The function ran in ".
msg_format
Type: character. The formatting applied to the evaluation time, used by sprintf. Defaults to "%05.03f".
post_msg
Type: character. The message succeeding the time print. Defaults to ifelse(seconds == TRUE, " seconds.", " milliseconds.".
linebreak
Type: logical. Whether to add a line break after the printed message. Defaults to TRUE.

Value

The time needed for a function to run in milliseconds (or seconds).

Examples

Run this code
library(R.utils)
timer_func_print({for (i in 1:100) {rnorm(1)}}, seconds = TRUE)

Run the code above in your browser using DataLab