Expand description
Throughput measurement for criterion.rs using decimal multiple-byte units.
By default, using criterion.rs throughput measurement gives results in binary multiple-byte units, so KiB/s, MiB/s, etc. Some people, like me, prefer to use the more intuitive decimal multiple-byte units of KB/s, MB/s, and so on. This crate enables that.
§Usage
You need to:
- Use the custom measurement type
criterion_decimal_throughput::Criterionfrom this crate, exposed with thedecimal_byte_measurementfunction. - Enable throughput measurement in the benchmark group with
criterion::BenchmarkGroup::throughput.
§Example
use criterion::{criterion_group, criterion_main};
use criterion_decimal_throughput::{Criterion, decimal_byte_measurement};
fn example_bench(c: &mut Criterion) {
let mut group = c.benchmark_group("example_name");
group.throughput(criterion::Throughput::Bytes(/* Your input size here */ 1_000_000u64));
// Add your benchmarks to the group here...
group.finish();
}
criterion_group!(
name = example;
config = decimal_byte_measurement();
targets = example_bench
);
criterion_main!(example);§With custom config
If you use a custom configuration for your benches and want to combine it with this crate, the decimal_byte_measurement will not
do, as it includes the default Criterion config. Instead, register the measurement with criterion::Criterion::with_measurement:
§Example
use core::time::Duration;
use criterion::{criterion_group, criterion_main};
use criterion_decimal_throughput::{Criterion, DecimalByteMeasurement};
fn example_bench(c: &mut Criterion) {
// ...
}
// Your custom configuration would come here.
// As an example, we use a configuration that sets a non-default warm-up time of 10 seconds.
pub fn my_custom_config() -> Criterion {
criterion::Criterion::default()
.warm_up_time(Duration::from_secs(10))
.with_measurement(DecimalByteMeasurement::new())
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ This enables the crate.
}
criterion_group!(
name = example;
config = my_custom_config();
targets = example_bench
);
criterion_main!(example);§Origin
Related criterion.rs issue: https://github.com/bheisler/criterion.rs/issues/581.
Structs§
- Decimal
Byte Measurement - Measurement type for decimal multiple-byte units.
Functions§
- decimal_
byte_ measurement - Construct a default
criterion::Criterionmanager withDecimalByteMeasurement.
Type Aliases§
- Criterion
- Shorthand for the criterion manager with
DecimalByteMeasurement.