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

Optimize udivmod_1e19 function #27

Merged
merged 2 commits into from
Aug 22, 2021

Conversation

Kogia-sima
Copy link
Contributor

This PR optimize udivmod_1e19 function based on the algorithm provided in [1]. This optimization dramatically improve performance of formatting u128 type.

Performance

previous results

test bench_itoa_fmt::bench_u128_0     ... bench:          19 ns/iter (+/- 0)
test bench_itoa_fmt::bench_u128_max   ... bench:         423 ns/iter (+/- 3)
test bench_itoa_write::bench_u128_0   ... bench:          17 ns/iter (+/- 0)
test bench_itoa_write::bench_u128_max ... bench:         422 ns/iter (+/- 13)
test bench_std_fmt::bench_u128_0      ... bench:          78 ns/iter (+/- 2)
test bench_std_fmt::bench_u128_max    ... bench:         514 ns/iter (+/- 9)

new results

test bench_itoa_fmt::bench_u128_0     ... bench:          19 ns/iter (+/- 3)
test bench_itoa_fmt::bench_u128_max   ... bench:          75 ns/iter (+/- 3)
test bench_itoa_write::bench_u128_0   ... bench:          17 ns/iter (+/- 1)
test bench_itoa_write::bench_u128_max ... bench:          75 ns/iter (+/- 3)
test bench_std_fmt::bench_u128_0      ... bench:          74 ns/iter (+/- 3)
test bench_std_fmt::bench_u128_max    ... bench:         512 ns/iter (+/- 19)

Reference

[1] T. Granlund and P. Montgomery, “Division by Invariant Integers Using Multiplication” in Proc. of the SIGPLAN94 Conference on Programming Language Design and Implementation, 1994, pp. 61–72

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 2886a30 into dtolnay:master Aug 22, 2021
@dtolnay
Copy link
Owner

dtolnay commented Aug 22, 2021

Published in itoa 0.4.8.

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