#18304: Integer and Rational comparisons
-------------------------------------+-------------------------------------
       Reporter:  vdelecroix         |        Owner:
           Type:  enhancement        |       Status:  needs_work
       Priority:  major              |    Milestone:  sage-6.9
      Component:  performance        |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Vincent Delecroix  |    Reviewers:
Report Upstream:  N/A                |  Work issues:
         Branch:                     |       Commit:
  u/vdelecroix/18304                 |  554c4358bc0e470ec0c72c2a24251f4a6978a12e
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by vdelecroix):

 * milestone:  sage-6.7 => sage-6.9


Old description:

> Comparing integers is very fast, comparing rationals is very fast but
> comparing integer with rational is about 5x slower:
> {{{
> sage: a = 1; b = 18
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 64.3 ns per loop
> sage: a = QQ(1); b = QQ(18)
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 88.4 ns per loop
> sage: a = 1; b = QQ(18)
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 416 ns per loop
> }}}
>
> With the branch applied all comparisons involving only Sage integers,
> Sage rationals and Python int/long are about the same time. With the
> branch applied, I got
>
> {{{
> sage: a = 1; b = 18
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 62.2 ns per loop
> sage: a = QQ(1); b = QQ(18)
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 65.3 ns per loop
> sage: a = 1; b = QQ(18)
> sage: timeit("a < b", number=500000, repeat=100)
> 500000 loops, best of 100: 82.8 ns per loop
> }}}

New description:

 Comparing integers is very fast, comparing rationals is very fast but
 comparing integer with rational is about 5x slower:
 {{{
 sage: a = 1; b = 18
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 64.3 ns per loop
 sage: a = QQ(1); b = QQ(18)
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 88.4 ns per loop
 sage: a = 1; b = QQ(18)
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 416 ns per loop
 }}}

 Upstream mpir pull request for the `mpq_cmp_mpz` function:

     [https://github.com/wbhart/mpir/pull/157
 https://github.com/wbhart/mpir/pull/157]

--

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