#14585: Make lazy_format and lazy_string faster
-------------------------------------+-------------------------------------
Reporter: SimonKing | Owner: robertwb
Type: defect | Status: needs_work
Priority: major | Milestone: sage-6.4
Component: coercion | Resolution:
Keywords: | Merged in:
Authors: Simon King | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/SimonKing/Make_lazy_format_faster| 2eab18c54d05655257042468503dcf75c3baaa33
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by SimonKing):
Replying to [comment:45 jdemeyer]:
> For `__richcmp__`, you can just use
> {{{
> return PyObject_RichCompare(self.value, other, v)
> }}}
I tried it, and to my surprise it seems slightly slower:
Current code
{{{
sage: from sage.misc.lazy_string import lazy_string
sage: f = lambda: "laziness"
sage: s = lazy_string(f)
sage: %timeit s < 'laziness'
The slowest run took 17.05 times longer than the fastest. This could mean
that an intermediate result is being cached
1000000 loops, best of 3: 294 ns per loop
sage: %timeit s <= 'aziness'
The slowest run took 19.35 times longer than the fastest. This could mean
that an intermediate result is being cached
1000000 loops, best of 3: 308 ns per loop
sage: %timeit s == 'laziness'
The slowest run took 20.48 times longer than the fastest. This could mean
that an intermediate result is being cached
1000000 loops, best of 3: 291 ns per loop
sage: %timeit s != 'aziness'
The slowest run took 40.70 times longer than the fastest. This could mean
that an intermediate result is being cached
1000000 loops, best of 3: 293 ns per loop
}}}
With `PyObject_RichCompare`:
{{{
sage: from sage.misc.lazy_string import lazy_string
sage: f = lambda: "laziness"
sage: s = lazy_string(f)
sage: %timeit s < 'laziness'
The slowest run took 17.50 times longer than the fastest. This could mean
that an intermediate result is being cached
1000000 loops, best of 3: 341 ns per loop
sage: %timeit s <= 'aziness'
The slowest run took 20.08 times longer than the fastest. This could mean
that an intermediate result is being cached
1000000 loops, best of 3: 344 ns per loop
sage: %timeit s == 'laziness'
The slowest run took 20.68 times longer than the fastest. This could mean
that an intermediate result is being cached
1000000 loops, best of 3: 334 ns per loop
sage: %timeit s != 'aziness'
The slowest run took 21.79 times longer than the fastest. This could mean
that an intermediate result is being cached
1000000 loops, best of 3: 328 ns per loop
}}}
So, we shouldn't do that.
--
Ticket URL: <http://trac.sagemath.org/ticket/14585#comment:51>
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.