#13352: Running time improvement of the bitset_len method
---------------------------------+----------------------------
Reporter: dcoudert | Owner: jason
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-5.12
Component: misc | Resolution:
Keywords: | Merged in:
Authors: David Coudert | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
---------------------------------+----------------------------
Changes (by dcoudert):
* cc: leif (added)
Old description:
> This patch improves the running time of the {{{bitset_len}}} method by
> using {{{__builtin_popcount()}}}.
>
> Before:
> {{{
> sage: B = Bitset('10'*10000)
> sage: len(B)
> 10000
> sage: %timeit len(B)
> 1000 loops, best of 3: 245 us per loop
> }}}
>
> After:
> {{{
> sage: B = Bitset('10'*10000)
> sage: len(B)
> 10000
> sage: %timeit len(B)
> 100000 loops, best of 3: 2.52 us per loop
> }}}
>
> APPLY:
>
> * [attachment:trac_13352_bitset_len_v2.patch]
New description:
This patch improves the running time of the {{{bitset_len}}} method by
using {{{__builtin_popcount()}}}.
Before:
{{{
sage: B = Bitset('10'*10000)
sage: len(B)
10000
sage: %timeit len(B)
1000 loops, best of 3: 245 us per loop
}}}
After:
{{{
sage: B = Bitset('10'*10000)
sage: len(B)
10000
sage: %timeit len(B)
100000 loops, best of 3: 2.52 us per loop
}}}
APPLY:
* [attachment:trac_13352_bitset_len_v3.patch]
--
Comment:
I have now implemented the function in C in file {{{popcount.h}}} with a
small wrapper. The result is a bit slower than without wrapper, but still
way faster than previous method.
{{{
sage: B = Bitset('00'*10000+'1')
sage: len(B)
1
sage: %timeit len(B)
1000000 loops, best of 3: 361 ns per loop
sage: B = Bitset('10'*10000)
sage: %timeit len(B)
100000 loops, best of 3: 3.03 us per loop
sage: B = Bitset('10'*1000000)
sage: len(B)
1000000
sage: %timeit len(B)
1000 loops, best of 3: 287 us per loop
}}}
I have used the {{{_WIN32}}} flag, but I'm not sure it's the good one. So
if one knows the best flag to use to detect when the
{{{__builtin_popcount}}} method is not available, please let me know.
--
Ticket URL: <http://trac.sagemath.org/ticket/13352#comment:9>
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/groups/opt_out.