Skip to content

Commit 3f1d2aa

Browse files
committed
Use more efficient scheme for display u128/i128
Add zero padding Add benchmarks for fmt u128 This tests both when there is the max amount of work(all characters used) And least amount of work(1 character used)
1 parent d62d3f7 commit 3f1d2aa

File tree

2 files changed

+283
-59
lines changed

2 files changed

+283
-59
lines changed

library/core/benches/fmt.rs

+29
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,32 @@ fn write_str_macro_debug(bh: &mut Bencher) {
108108
}
109109
});
110110
}
111+
112+
#[bench]
113+
fn write_u128_max(bh: &mut Bencher) {
114+
bh.iter(|| {
115+
std::hint::black_box(format!("{}", u128::MAX));
116+
});
117+
}
118+
119+
#[bench]
120+
fn write_u128_min(bh: &mut Bencher) {
121+
bh.iter(|| {
122+
let s = format!("{}", 0u128);
123+
std::hint::black_box(s);
124+
});
125+
}
126+
127+
#[bench]
128+
fn write_u64_max(bh: &mut Bencher) {
129+
bh.iter(|| {
130+
std::hint::black_box(format!("{}", u64::MAX));
131+
});
132+
}
133+
134+
#[bench]
135+
fn write_u64_min(bh: &mut Bencher) {
136+
bh.iter(|| {
137+
std::hint::black_box(format!("{}", 0u64));
138+
});
139+
}

0 commit comments

Comments
 (0)