#6118: [with second patch, needs review] integer shifting slow
------------------------------+---------------------------------------------
Reporter: robertwb | Owner: somebody
Type: defect | Status: new
Priority: major | Milestone: sage-4.0.1
Component: basic arithmetic | Keywords:
------------------------------+---------------------------------------------
Comment(by craigcitro):
I'm definitely happy with this patch. As Robert points out in the patch,
there are a few inconsistencies in some of the `integer.pyx` code -- for
instance, there are the incongruously named `_lshift` and `_rshift_`,
which are basically the same and are barely used. I've removed them,
cleaned up the bits of code that used them, and made one or two (morally)
small changes to Robert's `_shift_helper` code, such as some comments and
more error checking.
Interestingly, I'm having some funny results using `timeit` vs. `%timeit`,
namely that `timeit` tends to be inconsistent on timings this tiny:
{{{
sage: a = 123 ; b = 11
sage: timeit("a << b")
625 loops, best of 3: 200 ns per loop
sage: timeit("a << b")
625 loops, best of 3: 323 ns per loop
sage: timeit("a << b")
625 loops, best of 3: 371 ns per loop
sage: timeit("a << b")
625 loops, best of 3: 360 ns per loop
sage: timeit("a << b")
625 loops, best of 3: 360 ns per loop
sage: timeit("a << b")
625 loops, best of 3: 370 ns per loop
sage: timeit("a << b")
625 loops, best of 3: 368 ns per loop
sage: timeit("a << b")
625 loops, best of 3: 418 ns per loop
}}}
As you can see, it's generally around `368 ns`, but the timings have
several outliers. But IPython `%timeit` thinks the fast outlier is the
'''correct''' value!
{{{
sage: %timeit a << b
10000000 loops, best of 3: 188 ns per loop
sage: %timeit a << b
10000000 loops, best of 3: 187 ns per loop
}}}
I tend to trust it, because it's running a ton of loops -- maybe the fact
that my computer is doing several things at once is disturbing `timeit`?
Anyway, new patch attached. Robert, if you could look over the changes,
I'd say this is a positive review. It seems to give me a nominally faster
(around `5%`) timing than the previous version, but that's probably just
my computer being weird.
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6118#comment:4>
Sage <http://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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---