This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
| Author | gvanrossum |
|---|---|
| Recipients | facundobatista, gvanrossum, jyasskin, mark.dickinson, ncoghlan, rhettinger |
| Date | 2008年02月14日.17:08:53 |
| SpamBayes Score | 0.12961257 |
| Marked as misclassified | No |
| Message-id | <1203008934.92.0.672776563128.issue1682@psf.upfronthosting.co.za> |
| In-reply-to |
| Content | |
|---|---|
PS. I can shave off nearly 4 usec of the constructor like this: - self = super(Fraction, cls).__new__(cls) + if cls is Fraction: + self = object.__new__(cls) + else: + self = super().__new__(cls) This would seem to give an upper bound for the gain you can make by moving the check for instantiating an abstract class to C. Your call. I also found that F(2,3)+F(5,7) takes about 22 usecs (or 18 using the above hack). Inlining the common case for addition (Fraction+Fraction) made that go down to 14 usec (combined with the above hack): - __add__, __radd__ = _operator_fallbacks(_add, operator.add) + __xadd__, __radd__ = _operator_fallbacks(_add, operator.add) + def __add__(self, other): + if type(other) is Fraction: + na = self._numerator + da = self._denominator + nb = other._numerator + db = other._denominator + return Fraction(na*db + nb*da, da*db) + return self.__xadd__(other) + |
|
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008年02月14日 17:08:55 | gvanrossum | set | spambayes_score: 0.129613 -> 0.12961257 recipients: + gvanrossum, rhettinger, facundobatista, mark.dickinson, ncoghlan, jyasskin |
| 2008年02月14日 17:08:55 | gvanrossum | set | spambayes_score: 0.129613 -> 0.129613 messageid: <1203008934.92.0.672776563128.issue1682@psf.upfronthosting.co.za> |
| 2008年02月14日 17:08:54 | gvanrossum | link | issue1682 messages |
| 2008年02月14日 17:08:53 | gvanrossum | create | |