]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-35588: Speed up mod, divmod and floordiv operations for Fraction type (#11322)
authorStefan Behnel <stefan_ml@behnel.de>
Wed, 2 Jan 2019 12:22:06 +0000 (13:22 +0100)
committerSerhiy Storchaka <storchaka@gmail.com>
Wed, 2 Jan 2019 12:22:06 +0000 (14:22 +0200)
commit3a374e0c5abe805667b71ffaaa7614781101ff4c
tree5b88e9c84d19b725996059a1713d9b1536028980
parenta1d14253066f7dd60cfb465c6511fa565f312b42
bpo-35588: Speed up mod, divmod and floordiv operations for Fraction type (#11322)

* bpo-35588: Implement mod and divmod operations for Fraction type by spelling out the numerator/denominator calculation, instead of instantiating and normalising Fractions along the way. This speeds up '%' and divmod() by 2-3x.

* bpo-35588: Also reimplement Fraction.__floordiv__() using integer operations to make it ~4x faster.

* Improve code formatting.

Co-Authored-By: scoder <stefan_ml@behnel.de>
* bpo-35588: Fix return type of divmod(): the result of the integer division should be an integer.

* bpo-35588: Further specialise __mod__() and inline the original helper function _flat_divmod() since it's no longer reused.

* bpo-35588: Add some tests with large numerators and/or denominators.

* bpo-35588: Use builtin "divmod()" function for implementing __divmod__() in order to simplify the implementation, even though performance results are mixed.

* Rremove accidentally added empty line.

* bpo-35588: Try to provide more informative output on test failures.

* bpo-35588: Improve wording in News entry.

Co-Authored-By: scoder <stefan_ml@behnel.de>
* Remove stray space.
Lib/fractions.py
Lib/test/test_fractions.py
Misc/NEWS.d/next/Library/2018-12-26-10-55-59.bpo-35588.PSR6Ez.rst [new file with mode: 0644]