#18304: Integer and Rational comparisons
-------------------------------------+-------------------------------------
       Reporter:  vdelecroix         |        Owner:
           Type:  enhancement        |       Status:  needs_review
       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                 |  e03a26e63dd50f79fc7ada885daefd8c9970c482
   Dependencies:                     |     Stopgaps:
-------------------------------------+-------------------------------------
Changes (by vdelecroix):

 * status:  needs_work => needs_review


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
> }}}
>
> Upstream mpir pull request for the `mpq_cmp_mpz` function:
>
>     [https://github.com/wbhart/mpir/pull/157
> https://github.com/wbhart/mpir/pull/157]

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: 84 ns per loop
 sage: a = 1; b = QQ(18)
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 405 ns per loop
 }}}

 With the branch applied, it gets better
 {{{
 sage: a = 1; b = 18
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 64 ns per loop
 sage: a = QQ(1); b = QQ(18)
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 65.6 ns per loop
 sage: a = 1; b = QQ(18)
 sage: timeit("a < b", number=500000, repeat=100)
 500000 loops, best of 100: 87.1 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]

 Warning: if you pull the branch and run `make` then you will likely
 rebuild your whole Sage!

--

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