Skip to content

Commit

Permalink
Use more efficient scheme for display u128/i128
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
JulianKnodt committed Sep 28, 2020
1 parent d62d3f7 commit 3f1d2aa
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 3f1d2aa

Please sign in to comment.