1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 //! Benchmarking support
7 //! Benchmarks are split up into two parts: the functions to be benchmarked live here, which the benchmarking code itself lives in `benches/bench.rs`.
8 //! It's easier to write benchmarking code inside the main crate, where we have access to private items.
9 //! However, it's easier to integrate with Cargo and criterion if benchmarks live in a separate crate.
11 //! All benchmarks are defined as structs that implement either the [Benchmark] or [BenchmarkWithInput]
16 /// Trait for simple benchmarks
18 /// This supports simple benchmarks that don't require any input. Note: global setup can be done
19 /// in the `new()` method for the struct.
21 /// Perform the operations that we're benchmarking.
22 fn benchmarked_code(&self);
25 /// Trait for benchmarks that require input
27 /// This will run using Criterion's `iter_batched` function. Criterion will create a batch of
28 /// inputs, then pass each one to benchmark.
30 /// This supports simple benchmarks that don't require any input. Note: global setup can be done
31 /// in the `new()` method for the struct.
32 pub trait BenchmarkWithInput {
35 /// Generate the input (this is not included in the benchmark time)
36 fn generate_input(&self) -> Self::Input;
38 /// Perform the operations that we're benchmarking.
39 fn benchmarked_code(&self, input: Self::Input);