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: "benchmark"). In order to trigger benchmark, specify TRUE as a value of this option.

default

A default value for the chunk option that triggers the hook (default: NULL).

format

A function to format a benchmark result (default: format_benchmark). It must accept two arguments, where the first is the benchmark result and the second is the list of current chunk options. NULL suppresses printing.

.set

TRUE or FALSE to set the hook.

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 formatting 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"))


[Package chunkhooks version 0.0.1 Index]