Skip to content

Commit 4cf3dc1

Browse files
committed
Auto merge of #76017 - JulianKnodt:fmt_fast, r=nagisa
Use less divisions in display u128/i128 This PR is an absolute mess, and I need to test if it improves the speed of fmt::Display for u128/i128, but I think it's correct. It hopefully is more efficient by cutting u128 into at most 2 u64s, and also chunks by 1e16 instead of just 1e4. Also I specialized the implementations for uints to always be non-false because it bothered me that it was checked at all Do not merge until I benchmark it and also clean up the god awful mess of spaghetti. Based on prior work in #44583 cc: `@Dylan-DPC` Due to work on `itoa` and suggestion in original issue: r? `@dtolnay`
2 parents bad9ad0 + 3f1d2aa commit 4cf3dc1

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)