Changes between Initial Version and Version 2 of Ticket #11657


Ignore:
Timestamp:
08/24/11 19:55:11 (11 years ago)
Author:
rbeezer
Comment:

Patch generally improves speed of conveniences (constructors) for creating zero vectors. Fastest route seems to usually be the .zero_vector() method of a module, which just barely beats coercing a zero scalar into the module most of the time.

The zero_vector() *constructor function* now uses the .zero_vector() *method*, and the vector() method short-circuits to return a zero vector just as soon as possible. The multi-format capabilities of the vector() constructor require some necessary overhead, which seems to be a constant 30 micro-seconds on my machine.

Additions to documentation provide advice for the truly speed-hungry.

4.7.1, without patch:

sage: n = 1000
sage: timeit("(ZZ^n).zero_vector()")
625 loops, best of 3: 69.9 µs per loop
sage: timeit("(ZZ^n)(0)")
625 loops, best of 3: 74.6 µs per loop
sage: timeit("zero_vector(ZZ, n)")
125 loops, best of 3: 2.55 ms per loop
sage: timeit("vector(ZZ, n)")
125 loops, best of 3: 2.52 ms per loop

sage: n = 10000
sage: timeit("(ZZ^n).zero_vector()")
625 loops, best of 3: 613 µs per loop
sage: timeit("(ZZ^n)(0)")
625 loops, best of 3: 617 µs per loop
sage: timeit("zero_vector(ZZ, n)")
25 loops, best of 3: 24.8 ms per loop
sage: timeit("vector(ZZ, n)")
25 loops, best of 3: 24.9 ms per loop

4.7.1, with patch:

sage: n = 1000
sage: timeit("(ZZ^n).zero_vector()")
625 loops, best of 3: 73.9 µs per loop
sage: timeit("(ZZ^n)(0)")
625 loops, best of 3: 77.2 µs per loop
sage: timeit("zero_vector(ZZ, n)")
625 loops, best of 3: 78.1 µs per loop
sage: timeit("vector(ZZ, n)")
625 loops, best of 3: 109 µs per loop

sage: n = 10000
sage: timeit("(ZZ^n).zero_vector()")
625 loops, best of 3: 624 µs per loop
sage: timeit("(ZZ^n)(0)")
625 loops, best of 3: 621 µs per loop
sage: timeit("zero_vector(ZZ, n)")
625 loops, best of 3: 624 µs per loop
sage: timeit("vector(ZZ, n)")
625 loops, best of 3: 654 µs per loop

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #11657

    • Property Status changed from new to needs_review
    • Property Authors changed from to Rob Beezer
  • Ticket #11657 – Description

    initial v2  
    1111
    1212I didn't realize that the special case of the zero vector is incredibly slow for the {{{vector}}} function.  This needs to be fixed.
     13
     14'''Apply''':
     15  1.  [attachment:trac_11657-zero-vector-speedup.patch]