cppalliance / decimal

A C++14 implementation of IEEE 754 decimal floating point numbers
https://cppalliance.org/decimal/decimal.html
Boost Software License 1.0
17 stars 1 forks source link

Improve digit counting methods #646

Closed mborland closed 3 weeks ago

mborland commented 3 weeks ago

Currently we use binary search tree to figure out the number of digits in a number. Looks like in the case of std::uint32_t we could covert to log calculation with a >15% speedup. I expect similar speedups for uint64_t and __uint128_t where it is more desparately needed.

Closes: #643

mborland commented 3 weeks ago

Benchmarks showed improvement for the operation, but when run inside the decimal benchmarks it caused decimal32 to slow down by greater than a factor of 2. Continuing to investigate with uint64_t since that has many more operations in the search tree.

mborland commented 3 weeks ago

Improvements for uint64_t were inconclusive, but using the same method for computing log on uint128_t yielded an about 8% improvement.

codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.7%. Comparing base (b4b08c2) to head (6740d37).

:exclamation: Current head 6740d37 differs from pull request most recent head fe31a35

Please upload reports for the commit fe31a35 to get more accurate results.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/cppalliance/decimal/pull/646/graphs/tree.svg?width=650&height=150&src=pr&token=drvY8nnV5S&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cppalliance)](https://app.codecov.io/gh/cppalliance/decimal/pull/646?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cppalliance) ```diff @@ Coverage Diff @@ ## develop #646 +/- ## ======================================= Coverage 98.7% 98.7% ======================================= Files 219 220 +1 Lines 15717 15717 Branches 1720 1720 ======================================= Hits 15497 15497 Misses 220 220 ``` | [Files](https://app.codecov.io/gh/cppalliance/decimal/pull/646?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cppalliance) | Coverage Δ | | |---|---|---| | [...lude/boost/decimal/detail/integer\_search\_trees.hpp](https://app.codecov.io/gh/cppalliance/decimal/pull/646?src=pr&el=tree&filepath=include%2Fboost%2Fdecimal%2Fdetail%2Finteger_search_trees.hpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cppalliance#diff-aW5jbHVkZS9ib29zdC9kZWNpbWFsL2RldGFpbC9pbnRlZ2VyX3NlYXJjaF90cmVlcy5ocHA=) | `100.0% <100.0%> (ø)` | | | [test/compare\_num\_digits.cpp](https://app.codecov.io/gh/cppalliance/decimal/pull/646?src=pr&el=tree&filepath=test%2Fcompare_num_digits.cpp&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cppalliance#diff-dGVzdC9jb21wYXJlX251bV9kaWdpdHMuY3Bw) | `100.0% <100.0%> (ø)` | | ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/cppalliance/decimal/pull/646?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cppalliance). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cppalliance) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/cppalliance/decimal/pull/646?dropdown=coverage&src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cppalliance). Last update [b4b08c2...fe31a35](https://app.codecov.io/gh/cppalliance/decimal/pull/646?dropdown=coverage&src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cppalliance). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=cppalliance).
mborland commented 3 weeks ago

Replaced by different method in: https://github.com/cppalliance/decimal/pull/647