commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gilles <>
Subject Re: [math] matrix multiplication surprisingly slow?
Date Tue, 05 Apr 2016 18:36:34 GMT

On Tue, 5 Apr 2016 15:43:04 +0100, Chris Lucas wrote:
> I recently ran a benchmark comparing the performance math commons 
> 3.6.1's
> linear algebra library to the that of scala Breeze (
> I looked at det, inverse, Cholesky factorization, addition, and
> multiplication, including matrices with 10, 100, 500, and 1000 
> elements,
> with symmetric, non-symmetric, and non-square cases where applicable.

It would be interesting to add this to the CM documentation:

> In general, I was pleasantly surprised: math commons performed about 
> as
> well as Breeze, despite the latter relying on native libraries. There 
> was
> one exception, however:
>     m0.multiply(m1)
> where m0 and m1 are both Array2DRowRealMatrix instances. It scaled 
> very
> poorly in math commons, being much slower than nominally more 
> expensive
> operations like inv and the Breeze implementation. Does anyone have a
> thought as to what's going on?

Could your provide more information such as a plot of performance vs 
A self-contained and minimal code to run would be nice too.
See the CM micro-benchmarking tool here:
And an example of how to use it:

> In case it's useful, one representative test
> involves multiplying two instances of
>     new Array2DRowRealMatrix(matVals)
> where matVals is 1000x1000 entries of math.random and the second 
> instance
> is created as part of the loop. This part of the benchmark is not 
> specific
> to the expensive multiplication step, and takes very little time 
> relative
> to the multiplication itself. I'm using System.nanotime for the 
> timing, and
> take the average time over several consecutive iterations, on a 3.5 
> GHz
> Intel Core i7, Oracle JRE (build 1.8.0_05-b13).

You might want to confirm the behaviour using JMH (becoming the Java 
for benchmarking):

Best regards,

> Thanks,
> Chris

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message