Search code examples
rustbenchmarking

What is the meaning of the Bencher.bytes?


I found this benchmark code:

#[bench]
fn bench_str_parse(b: &mut Bencher) {
    assert_eq!(str_parse(EXAMPLE_TIMESTAMP), EXPECTED_TIMESTAMP);
    b.bytes = EXAMPLE_TIMESTAMP.len() as u64;
    b.iter(|| str_parse(black_box(EXAMPLE_TIMESTAMP)));
}

The code assigns a number to b.bytes, with b having the type test::Bencher. What is the meaning of that field?


Solution

  • What is means of the "Bencher.bytes" ?

    If the concept of throughput is relevant to what you're benching (which is the case for parsing strings, to an extent) you can set the bencher.bytes field to the amount of data used / consumed per iteration, and at the end the benchmark report will print a throughput in bytes/second or somesuch.