You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use Fraction's private attributes in arithmetic methods
That's slightly faster for small components.
Before:
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = F(6, 5)' 'a + b'
20000 loops, best of 11: 12.1 usec per loop
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = 7' 'a + b'
20000 loops, best of 11: 11.4 usec per loop
After:
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = F(6, 5)' 'a + b'
50000 loops, best of 11: 9.74 usec per loop
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = 7' 'a + b'
20000 loops, best of 11: 16.5 usec per loop
On the master:
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = F(6, 5)' 'a + b'
50000 loops, best of 11: 9.61 usec per loop
$ ./python -m timeit -r11 -s 'from fractions import Fraction as F' \
-s 'a = F(10, 3)' -s 'b = 7' 'a + b'
50000 loops, best of 11: 9.11 usec per loop
0 commit comments