[issue37836] Support .as_integer_ratio() in fractions.Fraction

Jeroen Demeyer report at bugs.python.org
Mon Aug 19 05:08:06 EDT 2019


Jeroen Demeyer <jeroen.k.demeyer at gmail.com> added the comment:

> I afraid this can slow down the Fraction constructor.

No, it doesn't! It even speeds up the constructor in some cases:

./python -m perf timeit --duplicate 200 -s 'from fractions import Fraction; x = 1' 'Fraction(x)'
BEFORE: Mean +- std dev: 826 ns +- 20 ns
AFTER:  Mean +- std dev: 814 ns +- 17 ns

./python -m perf timeit --duplicate 200 -s 'from fractions import Fraction; x = 1' 'Fraction(x, x)'
BEFORE: Mean +- std dev: 1.44 us +- 0.03 us
AFTER:  Mean +- std dev: 1.46 us +- 0.02 us

./python -m perf timeit --duplicate 200 -s 'from fractions import Fraction; x = Fraction(1)' 'Fraction(x)'
BEFORE: Mean +- std dev: 1.64 us +- 0.03 us
AFTER:  Mean +- std dev: 1.30 us +- 0.04 us

./python -m perf timeit --duplicate 200 -s 'from fractions import Fraction; x = Fraction(1)' 'Fraction(x, x)'
BEFORE: Mean +- std dev: 3.03 us +- 0.05 us
AFTER:  Mean +- std dev: 2.34 us +- 0.06 us

./python -m perf timeit --duplicate 200 -s 'from fractions import Fraction; x = 1.0' 'Fraction(x)'
BEFORE: Mean +- std dev: 1.82 us +- 0.02 us
AFTER:  Mean +- std dev: 1.29 us +- 0.04 us

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37836>
_______________________________________


More information about the Python-bugs-list mailing list