Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use different buffer size for every integer type #16

Merged
merged 4 commits into from
Mar 22, 2018
Merged

Use different buffer size for every integer type #16

merged 4 commits into from
Mar 22, 2018

Conversation

Object905
Copy link
Contributor

Allows to save some stack space. Useful with no_std. No public API changes.

Maximum lengths was generated with this.

Benchmarks are:

Before:

test bench_itoa_fmt::bench_i16_0      ... bench:           9 ns/iter (+/- 0)
test bench_itoa_fmt::bench_i16_min    ... bench:          12 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u128_0     ... bench:          12 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u128_max   ... bench:         254 ns/iter (+/- 2)
test bench_itoa_fmt::bench_u64_0      ... bench:           8 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u64_half   ... bench:          24 ns/iter (+/- 1)
test bench_itoa_fmt::bench_u64_max    ... bench:          20 ns/iter (+/- 0)
test bench_itoa_write::bench_i16_0    ... bench:           9 ns/iter (+/- 0)
test bench_itoa_write::bench_i16_min  ... bench:          12 ns/iter (+/- 0)
test bench_itoa_write::bench_u128_0   ... bench:          12 ns/iter (+/- 0)
test bench_itoa_write::bench_u128_max ... bench:         253 ns/iter (+/- 5)
test bench_itoa_write::bench_u64_0    ... bench:           8 ns/iter (+/- 0)
test bench_itoa_write::bench_u64_half ... bench:          24 ns/iter (+/- 0)
test bench_itoa_write::bench_u64_max  ... bench:          21 ns/iter (+/- 0)

After:

test bench_itoa_fmt::bench_i16_0      ... bench:           9 ns/iter (+/- 0)
test bench_itoa_fmt::bench_i16_min    ... bench:          12 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u128_0     ... bench:          12 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u128_max   ... bench:         254 ns/iter (+/- 2)
test bench_itoa_fmt::bench_u64_0      ... bench:           8 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u64_half   ... bench:          14 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u64_max    ... bench:          20 ns/iter (+/- 0)
test bench_itoa_write::bench_i16_0    ... bench:           9 ns/iter (+/- 0)
test bench_itoa_write::bench_i16_min  ... bench:          12 ns/iter (+/- 1)
test bench_itoa_write::bench_u128_0   ... bench:          11 ns/iter (+/- 0)
test bench_itoa_write::bench_u128_max ... bench:         254 ns/iter (+/- 2)
test bench_itoa_write::bench_u64_0    ... bench:           8 ns/iter (+/- 0)
test bench_itoa_write::bench_u64_half ... bench:          13 ns/iter (+/- 0)
test bench_itoa_write::bench_u64_max  ... bench:          21 ns/iter (+/- 0)

After #[inline]:

test bench_itoa_fmt::bench_i16_0      ... bench:           8 ns/iter (+/- 0)
test bench_itoa_fmt::bench_i16_min    ... bench:          11 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u128_0     ... bench:          11 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u128_max   ... bench:         249 ns/iter (+/- 3)
test bench_itoa_fmt::bench_u64_0      ... bench:           8 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u64_half   ... bench:          13 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u64_max    ... bench:          19 ns/iter (+/- 1)
test bench_itoa_write::bench_i16_0    ... bench:           9 ns/iter (+/- 0)
test bench_itoa_write::bench_i16_min  ... bench:          11 ns/iter (+/- 0)
test bench_itoa_write::bench_u128_0   ... bench:          11 ns/iter (+/- 0)
test bench_itoa_write::bench_u128_max ... bench:         250 ns/iter (+/- 9)
test bench_itoa_write::bench_u64_0    ... bench:           8 ns/iter (+/- 0)
test bench_itoa_write::bench_u64_half ... bench:          13 ns/iter (+/- 0)
test bench_itoa_write::bench_u64_max  ... bench:          19 ns/iter (+/- 0)

src/lib.rs Outdated
#[cfg(target_pointer_width = "32")]
impl_Integer!(isize, usize as u32);
impl_Integer!( I32_MAX_LEN => isize, U32_MAX_LEN => usize as u32);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the space before I32_MAX_LEN.

src/lib.rs Outdated
const I128_MAX_LEN: usize = 40;

#[cfg(all(feature = "i128"))]
impl_Integer!(private U128_MAX_LEN => u64, I128_MAX_LEN => u64 as u64);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think rather than having 3 different implementations of IntegerPrivate for u64 for the three different array lengths, we should have just IntegerPrivate<[u8; U64_MAX_LEN]> and have casts or whatever in the 128-bit impls to leverage that one u64 impl. Is it possible to make that work?

Copy link
Owner

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay dtolnay merged commit ce0dc04 into dtolnay:master Mar 22, 2018
@dtolnay
Copy link
Owner

dtolnay commented Mar 22, 2018

I released this improvement in 0.4.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants