Debian Codegraph @

benches/display.rs

raw
1 #![allow(missing_docs)]
2
3 use std::{env, fmt, hint::black_box};
4
5 struct ByteSizeAlwaysPad(bytesize::ByteSize);
6
7 impl fmt::Display for ByteSizeAlwaysPad {
8 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
9 f.pad(&self.0.display().to_string())
10 }
11 }
12
13 #[divan::bench]
14 fn display_inner_display() {
15 black_box(format!(
16 "{}",
17 black_box(bytesize::ByteSize::kib(42).display()),
18 ));
19 }
20
21 #[divan::bench]
22 fn display_bytesize_standard() {
23 black_box(format!(
24 "{}",
25 black_box(bytesize::ByteSize::kib(42).display()),
26 ));
27 }
28
29 #[divan::bench]
30 fn display_bytesize_custom() {
31 black_box(format!("|{:-^10}|", black_box(bytesize::ByteSize::kib(42))));
32 }
33
34 #[divan::bench]
35 fn display_always_pad_standard() {
36 black_box(format!(
37 "{}",
38 black_box(ByteSizeAlwaysPad(bytesize::ByteSize::kib(42))),
39 ));
40 }
41
42 #[divan::bench]
43 fn display_always_pad_custom() {
44 black_box(format!(
45 "|{:-^10}|",
46 black_box(ByteSizeAlwaysPad(bytesize::ByteSize::kib(42))),
47 ));
48 }
49
50 fn main() {
51 env::set_var("DIVAN_SAMPLE_COUNT", "1000");
52 divan::main();
53 }