Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

rust - 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?

question from:https://stackoverflow.com/questions/65918614/what-is-the-meaning-of-the-bencher-bytes

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...