benchmark {chunkhooks} | R Documentation |
Benchmark chunks
Description
hook_benchmark
sets a hook to benchmark chunks with the benchmark=TRUE
option. The name of the trigger chunk option can be changed via the
chunk_option
parameter. The result is printed right after chunk outputs.
See examples for the default printing format by format_benchmark
.
Usage
hook_benchmark(
trigger = "benchmark",
default = NULL,
format = format_benchmark,
.set = TRUE
)
format_benchmark(result, options)
benchmarks
Arguments
trigger |
A name of chunk option that triggers benchmark (default:
|
default |
A default value for the chunk option that |
format |
A function to format a benchmark result (default:
|
.set |
|
result |
A result of benchmark |
options |
A list of current chunk options |
Format
An object of class environment
of length 0.
Details
benchmarks
records the results of benchmarks from chunks as a list named by
chunk labels. If one requires complex formatting of benchmark results, then
suppress automatic formatting by hook_benchmark(format = NULL)
. Then,
retrieve benchmark results from benchmarks[["chunk-label"]]
. Furthermore,
format
can happen conditionally by utilizing current chunk options via
the second argument of the format
ting function.
Value
invisible hook function
Examples
# Set a hook that triggers benchmarks if the `time` chunk option is not `NULL`.
hook_benchmark("time")
# Example of the default output format
# Input is sec. Output is prettified.
format_benchmark(1234, options = list(label = "example-chunk"))