[issue1762] Inheriting from ABC slows Decimal down.

2008-02-09 Thread Raymond Hettinger
Raymond Hettinger added the comment: Whoa! I thought we had arrived at a decision to leave decimal alone. Please do not infect this module with numbers.py. -- nosy: +rhettinger __ Tracker <[EMAIL PROTECTED]> _

[issue1762] Inheriting from ABC slows Decimal down.

2008-02-09 Thread Jeffrey Yasskin
Jeffrey Yasskin added the comment: I measured various implementations of __instancecheck__ using `./python.exe -m timeit -s 'from rational import Rational; r = Rational(3, 2)' '...'` on my 2.33 GHz MacBook, with ... replaced by either isinstance(r, Rational) or isinstance(3, Rational) to measure

[issue1762] Inheriting from ABC slows Decimal down.

2008-01-08 Thread Christian Heimes
Christian Heimes added the comment: without abc: $ time ./python Lib/test/regrtest.py test_decimal real0m10.113s user0m9.685s sys 0m0.196s with numbers.Real subclass: $ time ./python Lib/test/regrtest.py test_decimal real0m16.232s user0m15.241s sys 0m0.384s Proposed pat

[issue1762] Inheriting from ABC slows Decimal down.

2008-01-08 Thread Christian Heimes
Christian Heimes added the comment: The patch implements the rich cmp slots for <, <=, > and >= required for numbers.Real. Added file: http://bugs.python.org/file9107/trunk_decimal_richcmp.patch __ Tracker <[EMAIL PROTECTED]> __

[issue1762] Inheriting from ABC slows Decimal down.

2008-01-08 Thread Guido van Rossum
Guido van Rossum added the comment: What change is responsible for the speedup? The cache check or removing type(instance) from the set? Since type(instance) is usually the same object as instance.__class__, the set will still have only one element (in particular for Decimal this is the case) so

[issue1762] Inheriting from ABC slows Decimal down.

2008-01-08 Thread Christian Heimes
Christian Heimes added the comment: __instancecheck__ contains unnecessary code. If we restrict ABCs to new style classes we could make the function faster: Old: def __instancecheck__(cls, instance): """Override for isinstance(instance, cls).""" return any(cls.__subclasschec

[issue1762] Inheriting from ABC slows Decimal down.

2008-01-08 Thread Jeffrey Yasskin
Jeffrey Yasskin added the comment: I've only verified the behavior on 2.6, but I suspect it's true for both. __ Tracker <[EMAIL PROTECTED]> __ ___ Python

[issue1762] Inheriting from ABC slows Decimal down.

2008-01-08 Thread Christian Heimes
Christian Heimes added the comment: Is this for 2.6 or 3.0? -- nosy: +tiran priority: -> high __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs

[issue1762] Inheriting from ABC slows Decimal down.

2008-01-08 Thread Jeffrey Yasskin
New submission from Jeffrey Yasskin: Adding numbers.Real to Decimal's base classes almost doubles the time its its test suite takes to run. A profile revealed that a large fraction of that slowdown was in __instancecheck__, but even after optimizing that, it's still about 25% slower. It looks lik