#9882: slow random_element() for integer mod ring
-------------------------------+-------------------
       Reporter:  dmharvey     |        Owner:  tbd
           Type:  defect       |       Status:  new
       Priority:  major        |    Milestone:
      Component:  performance  |   Resolution:
       Keywords:               |    Merged in:
        Authors:               |    Reviewers:
Report Upstream:  N/A          |  Work issues:
         Branch:               |       Commit:
   Dependencies:               |     Stopgaps:
-------------------------------+-------------------

Comment (by ppurka):

 Replying to [comment:4 mmezzarobba]:
 > Thanks for your reply, and... sorry for being thick, but I still don't
 understand! I get:
 > {{{
 > sage: %timeit ZZ.random_element(0, R.order()-1)
 > 1000000 loops, best of 3: 650 ns per loop
 > sage: a = (R.order()-1)
 > sage: %timeit R(a)
 > 1000000 loops, best of 3: 325 ns per loop
 > sage: a = (R.order()-1)//2
 > sage: %timeit R(a)
 > 1000000 loops, best of 3: 324 ns per loop
 > }}}
 > so I would hope for a total running time of the order of 1 µs + some
 overhead for my function

 With the `//` operator you are actually getting Sage integers, whereas I
 was getting Sage rationals with the `/` operator. That explains why the
 coercion to `Integers` was taking so much time.

 Perhaps the best way is to use gmp as you have done above.

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