#9885: slow coercion from integer mod ring to integer ring
-------------------------+-------------------------------------------------
       Reporter:         |        Owner:  tbd
  dmharvey               |       Status:  needs_review
           Type:         |    Milestone:
  defect                 |   Resolution:
       Priority:  major  |    Merged in:
      Component:         |    Reviewers:
  performance            |  Work issues:
       Keywords:         |       Commit:
        Authors:  Nils   |  c04c8b5cd99d9614d52dc65df8bb1b07a497ff5a
  Bruin                  |     Stopgaps:
Report Upstream:  N/A    |
         Branch:         |
  u/nbruin/9885          |
   Dependencies:         |
-------------------------+-------------------------------------------------

Comment (by nbruin):

 Replying to [comment:7 mmezzarobba]:
 > I already tried after seeing your version, and the hybrid solution was
 the slowest of the three (by a significant amount). I didn't try to
 understand why.

 Hm, something must have gone wrong in the hybridization then. With this
 test code:
 {{{
 def test1(n,x):
     cdef long N=n
     for i in range(N):
         t1(x)
 def test2(n,x):
     cdef long N=n
     for i in range(N):
         t2(x)
 def t1(o):
     cdef object A=getattr(o,"_integer_",None)
     if A is not None:
         return A
     else:
         return None
 def t2(o):
     try:
         return o._integer_
     except AttributeError:
         return None
 }}}
 I get
 {{{
 sage: R=GF(5)
 sage: a=R(1)
 sage: timeit('test1(100000,a)')
 125 loops, best of 3: 6.94 ms per loop
 sage: timeit('test2(100000,a)')
 125 loops, best of 3: 7.49 ms per loop
 sage: timeit('test1(100000,R)')
 5 loops, best of 3: 123 ms per loop
 sage: timeit('test2(100000,R)')
 5 loops, best of 3: 146 ms per loop
 }}}
 you see that `getattr` is consistently faster in looking up the attribute,
 and also how expensive it is to fail to find it. Other variants using
 `PyObject_GetAttr` etc. were a little slower still.

--
Ticket URL: <http://trac.sagemath.org/ticket/9885#comment:8>
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