# [Numpy-discussion] Numpy x Matlab: some synthetic benchmarks

Paulo J. S. Silva pjssilva at ime.usp.br
Wed Jan 18 09:04:00 CST 2006

```Em Qua, 2006-01-18 às 07:56 -0600, Bruce Southey escreveu:
> Hi,
> Thanks for doing this as it helps determine which approach to take
> when coding problems.  Could you add the Numeric and numarray to these
> benchmarks? If for no other reason to show the advantage of the new
> numpy.

I add a new table with the requested benchmarks below.

As you can see, numpy is always faster then numarray but slower than
Numeric in indexing. Numeric also seems to suffer less from the
transpose phenomenon.
>
> I am curious in your code because you get very different results for
> matrix class depending on whether x or y is transposed. Do you first
> transpose the x or y first before the multiplication or is the
> multiplication done in place by just switching the indices?

I think the transpose problem is that the code makes a copy of the array
before calling blas (to make it fit the blas call). Actually if you
change the code from

dot(transpose(A), b)

to

M = transpose(A).copy()
dot(M, b)

the time spend in the operation doesn't change.

I am also sending my Python benchmark code attached to this message.
Anyone can used as you want (it requires numpy, Numeric and numarray
installed).

> Also, for x'*y, is the results for Dimension 50 and Dimension 500
> switched?

No the inner product results have different number of calls for all
dimensions. Hence you can't compare time between dimensions.

Paulo

--- New table ---

Obs: I have fixed a error in my old code that made the outer product for
numpy look bad. The way it was coded it was forcing an extra array copy
before the BLAS call.

Tests  x.T*y   x*y.T     A*x     A*B   A.T*x    half    2in2

Dimension: 5
Array   0.94	0.25	0.22	0.27	1.08	0.93	1.10
Matrix  6.93	1.56	0.64	0.75	1.64	3.08	4.48
NumArr  2.87	0.63	0.62	0.68	8.24	7.22 1	1.37
Numeri  1.15	0.33	0.29	0.36	0.68	0.61	0.72
Matlab	1.88	0.44	0.41	0.35	0.37	1.20	0.98

Dimension: 50
Array   9.64	2.03	0.57	18.74	13.75	4.09	4.29
Matrix 82.98	3.70	1.04	19.87	14.58	6.35	7.91
NumArr 29.72	2.58	0.95	18.40	12.88	8.50	12.90
Numeri 11.97	2.21	0.61	17.71	9.98	1.04	3.22
Matlab 16.98	1.94	1.07	17.86	0.73	1.57	1.77

Dimension: 500
Array   1.22	8.97	2.02	165.03	19.99	3.96	4.25
Matrix 18.13	9.20	2.01	164.90	20.29	4.06	4.35
NumArr  3.16	9.02	2.09	164.83	21.59	4.29	5.72
Numeri  1.46	8.99	2.03	165.01	19.22	3.24	4.50
Matlab	2.09	6.07	2.17	169.45	2.10	2.56	3.06

```