#19108: Implement Python 3 style comparison in the coercion framework
-------------------------------------+-------------------------------------
       Reporter:  ohanar             |        Owner:
           Type:  enhancement        |       Status:  needs_review
       Priority:  major              |    Milestone:  sage-6.9
      Component:  coercion           |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  R. Andrew Ohana    |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/ohanar/python3stylecomparison    |  168fafb347a6afbdc96cae5bc27a4bea1c22f2e9
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by ohanar):

 Ok, some very quick performance tests, using the following class:
 {{{
 #!python
 class MyElt(Element):
     def _le_(self, other):
         return True
 P = Parent()
 e = MyElt(P)
 }}}
 With caching enabled I get the following:
 {{{
 #!python
 sage: timeit('e <= e', number=10**7, repeat=10)
 10000000 loops, best of 10: 301 ns per loop
 sage: timeit('e == e', number=10**7, repeat=10)
 10000000 loops, best of 10: 427 ns per loop
 }}}
 Without caching I get the following:
 {{{
 #!python
 sage: timeit('e <= e', number=10**7, repeat=10)
 10000000 loops, best of 10: 494 ns per loop
 sage: timeit('e == e', number=10**7, repeat=10)
 10000000 loops, best of 10: 636 ns per loop
 }}}

 Given that I've only implemented `_le_`, the equality operator will call
 the `_le_` method twice, so from both examples we can see that the call to
 that function takes around 130-140 ns. Hence, the actual raw time before
 we get to calling the element's `_le_` goes up from around 160-170 ns when
 caching on the parent to around 360-370 ns when not caching on the parent.

 Granted, I didn't do any real changes to the partial/total order
 resolution other than just disabling caching, so you could improve the
 non-cached situation a bit, but my guess is that you would only get it
 down to around 300 ns or so depending on the operator that is asked for
 and the operators the element class provides (obviously, if you asked for
 an operator that the underlying element class provides, then you could
 short circuit much faster, and get close to the uncached performance).

--
Ticket URL: <http://trac.sagemath.org/ticket/19108#comment:7>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.

Reply via email to