30
$\begingroup$

I recently got a trial version of both Mathematica 9 and MATLAB 13a for Windows. I was stunned by the performance difference in the Windows and the Mac version. It was a simple test in matrix multiplication. Here's the code:

a = RandomReal[{0,1},{1000,2000}];
b = RandomReal[{0,1},{2000,3000}];
Timing[a.b;]

On Windows, running on VMWare Fusion, the above code takes 0.17 second to complete, more or less same as MATLAB. But on the Mac, it takes 1.8 seconds, or 10 times longer to complete the calculation. Something is terribly wrong here. What can be the explanation for this discrepancy? (I have 12GB free RAM on my 2012 Mac Mini so we can rule out memory shortage).

Edit: here some benchmarking information. Windows is running in Bootcamp in the benchmark, not from VMWare Fusion:

                                Mac        Windows
                                -------    -------
Data Fitting                    0.666      0.468
Digits of Pi                    0.711      0.733
Discrete Fourier Transform      1.082      0.874
Eigenvalues of a Matrix         0.737      0.608
Elementary Function             1.072      0.780
Gamma Function                  0.532      0.655
Large Integer Multiplication    0.518      0.608
Matrix Arithmetic               1.         1.108
Matrix Multiplication           0.841      0.562
Matrix Transpose                0.889      0.842
Numerical Integration           1.083      0.764
Polynomial Expansion            0.118      0.094
Random Number Sort              1.459      1.061
Singular Value Decomposition    0.751      0.671
Solving a Linear System         0.767      0.655
------------------------------------------------
Total Time                     12.226     10.483
Benchmark Result                1.132      1.320

Mathematica on Mac seems to be a good 20% slower than on Windows.

$\endgroup$
  • 6
    $\begingroup$ I'm not on Mac so I can't test this, but I believe that on Windows Dot on packed reals is implemented as a fast Intel® Math Kernel Library call. I am guessing that on the Mac such a call isn't being used for some reason. Perhaps a driver or library is missing; perhaps the developers never bothered to implement it. $\endgroup$ – Mr.Wizard Aug 4 '13 at 19:42
  • 7
    $\begingroup$ Why not run Needs["Benchmarking`"];Benchmark[] for a full comparison? $\endgroup$ – cormullion Aug 4 '13 at 20:52
  • 3
    $\begingroup$ But I bet the graphs are prettier on Mac ;^) $\endgroup$ – Hector Aug 13 '13 at 4:05
  • 11
    $\begingroup$ You may want to use SeedRandom to make sure you are working on the same matrices. On your a.b example I could observe variations of up to 20% on just 10 trials. $\endgroup$ – A.G. Dec 16 '13 at 7:58
  • 3
    $\begingroup$ I had exactly the same set-up on an early 2014 MacBook Pro, on which I ran Mathematica in OS X as well as on Windows 8.1. And I found exactly the same characteristics: Mathematica ran faster in Windows 8.1 than in OS X. $\endgroup$ – Shredderroy Dec 29 '15 at 21:18
9
$\begingroup$

A couple of general points before I delve into the specifics of this question

1) There will always be some OS difference in behavior and performance, even on the same hardware. We hook into OS APIs where appropriate, and we generally use native system compilers. Thus, if there are real differences between compilers, they might appear in the product (and we might have to work around them, if there are serious bugs).

2) Timing has platform dependent behavior, and in particular is inappropriate for performance testing, because it is measuring "time spent on the CPU" which is defined differently on different platforms. On Windows, it is, I think, the largest time spent by any single core on the CPU. On Unix, it is the sum total of the times spent by each core. You can verify this by comparing Timing with AbsoluteTiming, which returns wall-clock time:

In[170]:= a = RandomReal[{0, 1}, {1000, 2000}];
b = RandomReal[{0, 1}, {2000, 3000}];
Timing[a.b;]
Out[172]= {0.38635, Null}

In[173]:= a = RandomReal[{0, 1}, {1000, 2000}];
b = RandomReal[{0, 1}, {2000, 3000}];
AbsoluteTiming[a.b;]
Out[175]= {0.106865, Null}

My MBP has 4 cores, and returns approximately 1/4 wall-clock time as CPU time, becuase matrix multiplication parallelizes very well. I'm guessing that on your Mac Mini you had 4 cores, so your factor 10 was really a factor of 2.5.

Now, why was Version 9 about 20% slower overall on OS X than Windows? I don't know very specifically, although I can reproduced that on my MBP. OTOH, Version 11.1 runs faster on OS X than Windows. Version 9 coincides with the period Apple head ceased developing GCC and was working to make clang a viable alternative to it. So probably Version 9 was slower on Mac simply because it was using an older compiler which didn't have as many optimizations.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.