diff options
| author | bors <bors@rust-lang.org> | 2025-06-20 02:55:43 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-06-20 02:55:43 +0000 |
| commit | 5b74275f89b6041bf2e9dc2abcf332e206d4cfca (patch) | |
| tree | 7623ccbff36799fffb5edee4326d9dd6fef3d3bd /compiler/rustc_codegen_ssa/src | |
| parent | 255aa220821c05c3eac7605fce4ea1c9ab2cbdb4 (diff) | |
| parent | 9b09948897886541bc4f31a9d07bf4a2e1680171 (diff) | |
| download | rust-5b74275f89b6041bf2e9dc2abcf332e206d4cfca.tar.gz rust-5b74275f89b6041bf2e9dc2abcf332e206d4cfca.zip | |
Auto merge of #142294 - GuillaumeGomez:specialize-tostring-on-128-integers, r=tgross35
Use a distinct `ToString` implementation for `u128` and `i128`
Part of https://github.com/rust-lang/rust/issues/135543.
Follow-up of rust-lang/rust#136264.
When working on https://github.com/rust-lang/rust/pull/142098, I realized that `i128` and `u128` could also benefit from a distinct `ToString` implementation so here it.
The last commit is just me realizing that I forgot to add the format tests for `usize` and `isize`.
Here is the bench comparison:
| bench name | last nightly | with this PR | diff |
|-|-|-|-|
| bench_i128 | 29.25 ns/iter (+/- 0.66) | 17.52 ns/iter (+/- 0.7) | -40.1% |
| bench_u128 | 34.06 ns/iter (+/- 0.21) | 16.1 ns/iter (+/- 0.6) | -52.7% |
I used this code to test:
```rust
#![feature(test)]
extern crate test;
use test::{Bencher, black_box};
#[inline(always)]
fn convert_to_string<T: ToString>(n: T) -> String {
n.to_string()
}
macro_rules! decl_benches {
($($name:ident: $ty:ident,)+) => {
$(
#[bench]
fn $name(c: &mut Bencher) {
c.iter(|| convert_to_string(black_box({ let nb: $ty = 20; nb })));
}
)+
}
}
decl_benches! {
bench_u128: u128,
bench_i128: i128,
}
```
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
0 files changed, 0 insertions, 0 deletions
