mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
36a805939e
The "dragon" `flt2dec` algorithm uses multi-precision multiplication by (sometimes large) powers of 10. It has precomputed some values to help with these calculations. BUT: * There is no need to store powers of 10 and 2 * powers of 10: it is trivial to compute the second from the first. * We can save a chunk of memory by storing powers of 5 instead of powers of 10 for the large powers (and just shifting by 2 as appropriate). * This also slightly speeds up the routines (by ~1-3%) since the intermediate products are smaller and the shift is cheap. In this PR, we remove the unnecessary constants and do the necessary adjustments. Relevant benchmarks before (on my Threadripper 3970X, x86_64-unknown-linux-gnu): ``` num::flt2dec::bench_big_shortest 137.92/iter +/- 2.24 num::flt2dec::strategy:🐉:bench_big_exact_12 2135.28/iter +/- 38.90 num::flt2dec::strategy:🐉:bench_big_exact_3 904.95/iter +/- 10.58 num::flt2dec::strategy:🐉:bench_big_exact_inf 47230.33/iter +/- 320.84 num::flt2dec::strategy:🐉:bench_big_shortest 3915.05/iter +/- 51.37 ``` and after: ``` num::flt2dec::bench_big_shortest 137.40/iter +/- 2.03 num::flt2dec::strategy:🐉:bench_big_exact_12 2101.10/iter +/- 25.63 num::flt2dec::strategy:🐉:bench_big_exact_3 873.86/iter +/- 4.20 num::flt2dec::strategy:🐉:bench_big_exact_inf 47468.19/iter +/- 374.45 num::flt2dec::strategy:🐉:bench_big_shortest 3877.01/iter +/- 45.74 ``` |
||
---|---|---|
.. | ||
benches | ||
src | ||
tests | ||
Cargo.toml |