bpo-37884: Optimize Fraction() and statistics.mean()#15329
bpo-37884: Optimize Fraction() and statistics.mean()#15329serhiy-storchaka wants to merge 5 commits into
Conversation
|
Am I right that this is the same as #15210 but with a private function instead? |
Sorry, something went wrong.
There was a problem hiding this comment.
I performed the same tests mentioned in the bpo issue to verify the results and compared between the latest commit to master (master:24fe46081b) to the PR branch (math-as_integer_ratio2:e658d19083).
OS: Arch Linux 5.2.8
CPU: Intel i5-4460
./python -m timeit -s "from fractions import Fraction as F" "F(123)"
200000 loops, best of 5
Master: 1.42 usec
PR: 1.55 usec
./python -m timeit -s "from fractions import Fraction as F" "F(1.23)"
100000 loops, best of 5
Master: 2.92 usec per loop
PR: 2.14 usec
./python -m timeit -s "from fractions import Fraction as F; f = F(22, 7)" "F(f)"
100000 loops, best of 5
Master: 2.47 usec
PR: 1.93 usec
./python -m timeit -s "from statistics import mean; a = [1]*1000" "mean(a)"
500 loops, best of 5
Master: 930 usec
PR: 640 usec
./python -m timeit -s "from statistics import mean; a = [1.23]*1000" "mean(a)"
200 loops, best of 5
Master: 1.31 msec
PR: 1.34 msec
./python -m timeit -s "from statistics import mean; from fractions import Fraction as F; a = [F(22, 7)]*1000" "mean(a)"
200 loops, best of 5
Master: 1.31 msec
PR: 1.09 msec
./python -m timeit -s "from statistics import mean; from decimal import Decimal as D; a = [D('1.23')]*1000" "mean(a)"
100 loops, best of 5
Master: 2.08 msec
PR: 2 msec
Sorry, something went wrong.
It also looks like the Travis doctest and docbuild was failing on the other PR. As far as functionality goes, the changes to the code in |
Sorry, something went wrong.
jdemeyer
left a comment
There was a problem hiding this comment.
Supporting arbitrary objects with an as_integer_ratio method is a non-trivial change and should be documented in a NEWS entry.
Sorry, something went wrong.
Yes, it is.
Agreed. |
Sorry, something went wrong.
https://bugs.python.org/issue37884