[Numpy-discussion] Slicing slower than matrix multiplication?

josef.pktd@gmai... josef.pktd@gmai...
Mon Dec 14 12:26:56 CST 2009


On Mon, Dec 14, 2009 at 12:51 PM, Francesc Alted <faltet@pytables.org> wrote:
> A Monday 14 December 2009 18:20:32 Jasper van de Gronde escrigué:
>> Francesc Alted wrote:
>> > A Monday 14 December 2009 17:09:13 Francesc Alted escrigué:
>> >> The things seems to be worst than 1.6x times slower for numpy, as matlab
>> >> orders arrays by column, while numpy order is by row.  So, if we want to
>> >> compare pears with pears:
>> >>
>> >> For Python 600x200:
>> >>    Add a row: 0.113243 (1.132425e-05 per iter)
>> >> For Matlab 600x200:
>> >>    Add a column: 0.021325 (2.132527e-006 per iter)
>> >
>> > Mmh, I've repeated this benchmark on my machine and got:
>> >
>> > In [59]: timeit E + Xi2[P/2]
>> > 100000 loops, best of 3: 2.8 µs per loop
>> >
>> > that is, very similar to matlab's 2.1 µs and quite far from the 11 µs you
>> > are getting for numpy in your machine...  I'm using a Core2 @ 3 GHz.
>>
>> I'm using Python 2.6 and numpy 1.4.0rc1 on a Core2 @ 1.33 GHz
>> (notebook). I'll have a look later to see if upgrading Python to 2.6.4
>> makes a difference.
>
> I don't think so.  Your machine is slow for nowadays standards, so the 5x
> slowness should be due to python/numpy overhead, but unfortunately nothing
> that could be solved magically by using a newer python/numpy version.

dot is slow on single cpu, older notebook with older atlas and low in
memory, (dot cannot multi-process).
it looks like adding a row is almost only overhead

for 600x200
>>> print "Dot product: %f" % dotProduct.timeit(N)
Dot product: 3.124008
>>> print "Add a row: %f" % additionRow.timeit(N)
Add a row: 0.080612
>>> print "Add a column: %f" % additionCol.timeit(N)
Add a column: 0.113229

for 60x20
>>> print "Dot product: %f" % dotProduct.timeit(N)
Dot product: 0.070933
>>> print "Add a row: %f" % additionRow.timeit(N)
Add a row: 0.058492
>>> print "Add a column: %f" % additionCol.timeit(N)
Add a column: 0.061401

600x2000  (dot may induce swapping to disc)
>>> print "Dot product: %f" % dotProduct.timeit(N)
Dot product: 43.114585
>>> print "Add a row: %f" % additionRow.timeit(N)
Add a row: 0.085261
>>> print "Add a column: %f" % additionCol.timeit(N)
Add a column: 0.122754
>>> print "Dot product: %f" % dotProduct.timeit(N)
Dot product: 35.232084

Josef

> --
> Francesc Alted
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>


More information about the NumPy-Discussion mailing list