mirror of
https://github.com/python/cpython.git
synced 2025-07-31 07:04:42 +00:00
Performance optimizations on Fraction's constructor.
./python.exe -m timeit -s 'from fractions import Fraction' 'Fraction(3)` 31.7 usec/loop -> 9.2 usec/loop ./python.exe -m timeit -s 'from fractions import Fraction' 'Fraction(3, 2)'` 27.7 usec/loop -> 9.32 usec/loop ./python.exe -m timeit -s 'from fractions import Fraction; f = Fraction(3, 2)' 'Fraction(f)' 31.9 usec/loop -> 14.3 usec/loop
This commit is contained in:
parent
abe3237187
commit
1c214d6c94
2 changed files with 13 additions and 15 deletions
|
@ -62,11 +62,11 @@ class FractionTest(unittest.TestCase):
|
|||
|
||||
self.assertRaisesMessage(ZeroDivisionError, "Fraction(12, 0)",
|
||||
F, 12, 0)
|
||||
self.assertRaises(TypeError, F, 1.5)
|
||||
self.assertRaises(TypeError, F, 1.5 + 3j)
|
||||
self.assertRaises(AttributeError, F, 1.5)
|
||||
self.assertRaises(AttributeError, F, 1.5 + 3j)
|
||||
|
||||
self.assertRaises(TypeError, F, F(1, 2), 3)
|
||||
self.assertRaises(TypeError, F, "3/2", 3)
|
||||
self.assertRaises(AttributeError, F, F(1, 2), 3)
|
||||
self.assertRaises(AttributeError, F, "3/2", 3)
|
||||
|
||||
def testFromString(self):
|
||||
self.assertEquals((5, 1), _components(F("5")))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue