tree: 0233390ea1e8b365a680143c35c1dd4a04f91e16 [path history] [tgz]
  1. examples/
  2. meta/
  3. src/
  4. BUILD.gn
  5. OWNERS
  6. README.md
src/developer/fuchsia-criterion/README.md

Introduction

Thin wrapper around the Criterion benchmark suite. This library is intended to be used as both a simple means of generating benchmark data for the dashboard, but also for local benchmarking with Criterion.

When generating Fuchsia benchmarking results (FuchsiaCriterion::default), the main function where this constructor is called will expect an output JSON path where it will store the results according to the Fuchsia benchmarking schema.

Benchmarking locally

A convenient way to make use of this crate for local benchmarking and fine-tuning is to pass --args=local_bench='true' to fx set. This will build fuchsia-criterion in a way that grants CMD-access to Criterion's interface from the fx shell.

For the following example's main.rs:

fn fibonacci(n: u64) -> u64 {
    match n {
        0 => 1,
        1 => 1,
        n => fibonacci(n - 1) + fibonacci(n - 2),
    }
}

fn main() {
    let mut c = FuchsiaCriterion::default();
    c.bench_function("fib 10", |b| b.iter(|| fibonacci(criterion::black_box(10))));
}

One can run:

$ fx set PRODUCT.BOARD --args=local_bench='true'
$ fx build
$ fx shell my_fib_bench -n