genFunTimer: Measure the time for calls to a function via 'trace'

View source: R/timeFun.R

genFunTimerR Documentation

Measure the time for calls to a function via trace

Description

This function arranges to monitor all calls (direct or indirect) to the specified function and measures the time each call took and stores that value which can be accessed at any time via the return value of this function. This use trace to run the timing code at the start and end of each call to the function.

To stop collecting the timings for the function, untrace it.

Usage

timeFun(fun, tmr = genFunTimer(), where = globalenv(), ...)

Arguments

fun

the function or name of the function to trace

tmr

the list of functions closure whose start and end elements will be used to compute and store the timings.

where

passed to trace

...

passed to trace

Value

A list with three elements, allfunctions.

start

use with trace to

Author(s)

Duncan Temple Lang

See Also

trace

Examples

tmr = timeFun(model.matrix)
lm(mpg ~ . , mtcars)
tmr$times()
invisible(replicate(10, lm(mpg ~ . , mtcars)))
tmr$times()

duncantl/CallCounter documentation built on Nov. 23, 2023, 3:38 p.m.