#17196: Relax assumptions on bitset operations
-------------------------------------+-------------------------------------
Reporter: jdemeyer | Owner:
Type: enhancement | Status: new
Priority: major | Milestone: sage-6.4
Component: misc | Resolution:
Keywords: | Merged in:
Authors: Jeroen Demeyer | Reviewers:
Report Upstream: N/A | Work issues:
Branch: public/17196 | Commit:
/relax-assumptions-on-bitset- | 3ae75a1f8fcfee0f78faf9bb4bb006149b535c45
operations | Stopgaps:
Dependencies: |
-------------------------------------+-------------------------------------
Comment (by SimonKing):
It seems that compilers are clever. On my 32-bit laptop:
{{{
sage: cython("""
....: cpdef unsigned int f1(unsigned int size):
....: return (size -1)/(8*sizeof(unsigned int)) +1
....: cpdef unsigned int f2(unsigned int size):
....: return ((size -1)>>5)+1
""")
sage: f1(89)
3L
sage: f2(89)
3L
sage: %timeit f1(89)
1000000 loops, best of 3: 376 ns per loop
sage: %timeit f2(89)
1000000 loops, best of 3: 371 ns per loop
sage: %timeit f1(89)
1000000 loops, best of 3: 377 ns per loop
sage: %timeit f2(89)
1000000 loops, best of 3: 375 ns per loop
sage: %timeit f1(189)
1000000 loops, best of 3: 377 ns per loop
sage: %timeit f2(189)
1000000 loops, best of 3: 382 ns per loop
}}}
{{{
sage: cython("""
....: cdef unsigned int bpl = 32
....: cdef unsigned int modbpl = 31
....: cpdef unsigned int f1(unsigned int size):
....: return size%bpl
....: cpdef unsigned int f2(unsigned int size):
....: return size&modbpl
....: """)
sage: f1(89)
25L
sage: f2(89)
25L
sage: %timeit f1(89)
1000000 loops, best of 3: 380 ns per loop
sage: %timeit f2(89)
1000000 loops, best of 3: 375 ns per loop
sage: %timeit f1(189)
1000000 loops, best of 3: 382 ns per loop
sage: %timeit f2(189)
1000000 loops, best of 3: 375 ns per loop
}}}
So, not really a difference...
--
Ticket URL: <http://trac.sagemath.org/ticket/17196#comment:13>
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.