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
.
hook_benchmark( trigger = "benchmark", default = NULL, format = format_benchmark, .set = TRUE ) format_benchmark(result, options) benchmarks
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 |
An object of class environment
of length 0.
invisible hook function
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.
# 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"))#> [1] "example-chunk: 20m 34s"