An Informal test to Compare Matlab, Mathematica and Maple for Matrix Rank Calculation.

 

How was this test done:

PC used is Intel Pentium 4, 1 CPU, 2.4 GHz, 1 GB RAM. XP home edition. SP2. Mathematica 5.2, Matlab 7,0, Maple 10.01

 

For each NxN matrix, about 5 tests ran for each matrix size per system, average value taken.

 

During running each test I did not use the PC in anyway so not to affect the test. No other programs where running.

 

In table below, the first column is N, the matrix size. All values in the matrix are in seconds.

 

 

Conclusion:

===========

 

Generation of random matrix:

----------------------------

Maple was close second to Matlab for smaller Matrix sizes, then Matab pulled further ahead as the matrix size increased more. But overall for all 3 systems, this part took insignificant amount of time compared to rank calculation. So this part did not affect the overall performance.

 

Rank calculation:

-----------------

Maple and Mathematica performance was very close to each others for small size matrices. Almost identical performance. This was up to matrix of size 2500.

 

Mathematica performance seemed to get a little better after that compared to Maple. At Matrix size 4000x4000 Maple test was terminated due to a failed memory error problem.  The amount of RAM needed should be 4000x4000x8x4= 512 MB. This error should not happen really, it seems like an internal problem in Maple since both Matlab and Mathematica were able to handle up to 5000x5000 matrices. Matlab for example I know for sure uses double for its numeric data (8 bytes), so this is the same memory requirement as Maple in this test.

 

Mathematica was almost 60% faster than Matlab for 5000x5000 matrix matrix rank calculation. This is a very good result for Mathematica.

 

Matlab was the fastest in all the tests for the Random matrix generation.

 

I hope someone can look into why Maple got this memory error at 4000 matrix size.

 

                       

     +--------------+---------------+--------------+---------------+

     |   Maple  gc  | Maple (no gc) | Mathematica  |  Matlab       |

     |----+----+----+----+-----+----+----+----+----+----+----+-----+

     |Rand|Rank|tot |Rand|Rank |tot |Rand|Rank|tot |Rand|Rank|tot  |

+----+--------------+----+-----+----+----+----+----+----+----+-----+

|500 |.031|.545|.56 |0.03|.531 |.56 |0.04|0.55|0.56|0.04|0.9 |0.94 |

+----+----+----+----+----+-----+----+----+----+----+----+----+-----+

|1000|0.11|3.74|3.84|0.1 |3.7  |3.8 |.2  |3.8 | 4  |.11 |5.7 |5.8  |

+----+----+----+----+----+-----+----+----+----+----+----+----+-----+

|1500|0.25|11.7|11.9|.23 |11.7 |11.9|.4  |12.3|12.7|.14 |22  |22.15|

+----+----+----+----+----+-----+----+----+----+----+----+----+-----+  

|2000|0.42|29.8|30.2|               |.75 |30  |31  |.26 |44  | 44.3|

+----+----+----+----+               +----+----+----+----+----+-----+

|2500|0.67|50.6|51.2| Difference    |1.2 |55  |56  |.34 |96  | 96.3|

+----+----+----+----+ too  small.   +----+----+----+----+----+-----+

|3000|0.98|94  |95  |               |1.8 |85  |87  |.47 |142 | 143 |

+----+----+----+----+               +----+----+----+----+----+-----+

|3500|1.3 |167 |170 |               |2.3 |132 |135 |.61 |262 | 263 |

+----+----+----+----+               +----+----+----+----+----+-----+

|4000|1.75|*   |    |               |3.27|236 |240 |.83 |340 | 341 |

+----+----+----+----+               +----+----+----+----+----+-----+

|4500|2.15|*   |    |               |3.98|304 |308 |.93 |545 | 546 |

+----+----+----+----+               +----+----+----+----+----+-----+

|5000|2.67|*   |    |               |4.7 |425 |430 |1.46|671 | 672 |

+----+----+----+----+---------------+----+----+----+----+----+-----+

                 ^                              ^              ^

                 |                              |              |

                Maple                      Mathematica       Matlab

 

(*): Maple gave this error:

Error, (in Matrix) not enough memory to allocate rtable

 

code used is shown below:

 

Maple:

======

 

> restart;

> kernelopts(gcfreq= 2^22):

> UseHardwareFloats:= true:

> gc():

>

> n:=3500:

> t0:= time():

>

> M:= LinearAlgebra:-RandomMatrix(

>      n

>     ,n

>     ,generator=0.0 .. 1

>     ,outputoptions=[datatype=float[8]]

> ):

>

> #gc():

> randTime:= time()-t0;

> LinearAlgebra:-LA_Main:-Rank(M):

> rankTime:= time()-(t0+randTime);

> total:=rankTime+randTime;

 

 

Mathematica:

============

 

Remove["Global`*"];

Share[];

n = 4000;

Timing[m = Table[Random[], {i, 1, n}, {j, 1, n}]; ]

Timing[MatrixRank[m]]

 

 

Matlab:

=======

n=5000;

t=cputime;

A=rand(n,n);

cputime-t

t=cputime;

rank(A); 

cputime-t

 

 

Nasser Abbasi