Skip to content

Optimize bignum implementation #12924

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

Merged
merged 2 commits into from
Mar 16, 2014
Merged

Optimize bignum implementation #12924

merged 2 commits into from
Mar 16, 2014

Conversation

Florob
Copy link
Contributor

@Florob Florob commented Mar 15, 2014

This is a minor optimization of the bignum module. The improvements mostly come from avoiding allocations and boundary checks. This also switches all of libnum to vec_ng::Vec.

@sfackler
Copy link
Member

#12837 switches libnum to Vec as well FYI

@emberian
Copy link
Member

@Florob do you have numbers for the improvements?

bors added a commit that referenced this pull request Mar 16, 2014
This is a minor optimization of the bignum module. The improvements mostly come from avoiding allocations and boundary checks. This also switches all of libnum to vec_ng::Vec.
@bors bors closed this Mar 16, 2014
@bors bors merged commit ce2ce24 into rust-lang:master Mar 16, 2014
@Florob
Copy link
Contributor Author

Florob commented Mar 16, 2014

@cmr I do. The first 7 are 3 BigUint x 3 BigUint (consiting of 3 or 4 BigDigits each) combined with the respective operation, per iteration. The later are from libnum.
Most improvements are minor (particularly considering deviation), others are quite nice.
This is measured on an AMD Phenom II X6 1100T system.

Before:

test bench_add    ... bench:       711 ns/iter (+/- 23)
test bench_bitand ... bench:       637 ns/iter (+/- 46)
test bench_bitor  ... bench:       703 ns/iter (+/- 50)
test bench_bitxor ... bench:       695 ns/iter (+/- 23)
test bench_div    ... bench:     12611 ns/iter (+/- 923)
test bench_mul    ... bench:     24591 ns/iter (+/- 1061)
test bench_sub    ... bench:       816 ns/iter (+/- 59)

test factorial_100 ... bench:     13476 ns/iter (+/- 626)
test fib_100       ... bench:      6679 ns/iter (+/- 294)
test shr           ... bench:      3079 ns/iter (+/- 184)
test to_str        ... bench:      6756 ns/iter (+/- 312)

After:

test bench_add    ... bench:       681 ns/iter (+/- 58)
test bench_bitand ... bench:       547 ns/iter (+/- 10)
test bench_bitor  ... bench:       640 ns/iter (+/- 39)
test bench_bitxor ... bench:       650 ns/iter (+/- 45)
test bench_div    ... bench:      8963 ns/iter (+/- 635)
test bench_mul    ... bench:     21779 ns/iter (+/- 998)
test bench_sub    ... bench:       729 ns/iter (+/- 40)

test factorial_100 ... bench:     13621 ns/iter (+/- 625)
test fib_100       ... bench:      6739 ns/iter (+/- 401)
test shr           ... bench:      2732 ns/iter (+/- 131)
test to_str        ... bench:      4769 ns/iter (+/- 279)

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.

6 participants