brainevent.benchmark_function

brainevent.benchmark_function#

brainevent.benchmark_function(fn, n_warmup, n_runs, n_batch_per_run=1, data=())[source]#

Benchmark a function and return timing statistics.

Parameters:
  • fn (Callable) – The callable to benchmark. It is invoked as fn(*data) and its result is used to seed the timing loop’s carry.

  • n_warmup (int) – Number of warmup runs (not timed).

  • n_runs (int) – Number of timed measurement intervals.

  • n_batch_per_run (int) – Number of back-to-back fn() calls issued within each timed interval before blocking. Default is 1, which blocks after every call and measures per-call latency. Values greater than 1 amortise blocking overhead across multiple kernel launches, which is useful for measuring throughput on asynchronous GPU/TPU execution. The reported times are always per-call (i.e. the interval time divided by n_batch_per_run).

  • data (Tuple) – Positional arguments forwarded to fn on every call. Default is the empty tuple () (fn is called with no arguments).

Returns:

(mean_time, std_time, min_time, max_time, output) where times are in seconds and represent per-call values.

Return type:

Tuple[float, float, float, float, Any]