Skip to content

Comparing integers to infinity is slow #33337

@saraedum

Description

@saraedum

Currently, comparisons involving infinities can be slow:

sage: %timeit 2 > oo  # slow
4.96 µs ± 35.1 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
sage: %timeit oo > oo  # ok
321 ns ± 4.57 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
sage: %timeit 1/2 > oo  # slow
5.95 µs ± 311 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
sage: o = RR(oo)
sage: %timeit o > oo  # slow
2.5 µs ± 26.8 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

It's probably a good idea to implement __richcmp__ for the infinity elements to special case a few of these obvious things.

CC: @roed314

Component: basic arithmetic

Issue created by migration from https://trac.sagemath.org/ticket/33337

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions