Skip to content

Commit

Permalink
Auto merge of #76017 - JulianKnodt:fmt_fast, r=nagisa
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Oct 4, 2020
2 parents bad9ad0 + 3f1d2aa commit 4cf3dc1
Show file tree
Hide file tree
Showing 2 changed files with 283 additions and 59 deletions.
29 changes: 29 additions & 0 deletions library/core/benches/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,32 @@ fn write_str_macro_debug(bh: &mut Bencher) {
}
});
}

#[bench]
fn write_u128_max(bh: &mut Bencher) {
bh.iter(|| {
std::hint::black_box(format!("{}", u128::MAX));
});
}

#[bench]
fn write_u128_min(bh: &mut Bencher) {
bh.iter(|| {
let s = format!("{}", 0u128);
std::hint::black_box(s);
});
}

#[bench]
fn write_u64_max(bh: &mut Bencher) {
bh.iter(|| {
std::hint::black_box(format!("{}", u64::MAX));
});
}

#[bench]
fn write_u64_min(bh: &mut Bencher) {
bh.iter(|| {
std::hint::black_box(format!("{}", 0u64));
});
}
Loading

0 comments on commit 4cf3dc1

Please sign in to comment.