## Linear Algebra on different platforms

3.23.09

In a recent project which required to be cross-platform I had the fun experience of seeing how different each platform is at doing basic (and not so basic) matrix operations. The current project had been originally written in Matlab and I have since then rewritten the project in C++ so that it could be enjoyed on Mac, Linux and iPhone. Clearly all three machines (MacBook Pro, Dell, and iPhone) have different processing speeds, however, Â what I discovered is that for some things speed alone is not the issue.

*Note: These values were generated on different processors and no attempt was made to see which one was ultimately faster. The idea was to see how, independently, each environment performed under complex matrix operations. All values are in seconds andÂ averagedÂ over 100 iterations.*

**Addition**

MxM | Matlab(Mac) | Matlab(Linux) | C++(Mac) | C++(iPhone) |
---|---|---|---|---|

121 | .15 | .015 | .0003 | .02 |

961 | 2.21 | .22 | .019 | 1.43 |

**Multiplication**

MxM | Matlab(Mac) | Matlab(Linux) | C++(Mac) | C++(iPhone) |
---|---|---|---|---|

121 | .47 | .061 | .0007 | .04 |

961 | 12.19 | 2.49 | .0396 | 1.87 |

Off the bat, many things can be seen. First Matlab on a Mac is far slower than on Linux. This is because Matlab basically operates inside an emulator under OSX. Although I do not have a Windows machine, I have strong doubts that Matlab runs even fastest there. Second is the good news that one can technically outperform Matlab using C++. Using the http://eigen.tuxfamily.org/ library basic addition is actually not only faster than Matlab, but the iPhone outperforms MatlabÂ runningÂ on OSX! Matlab should be ashamed that its product is slower on a Core 2 Duo than on a 500Mhz Arm chip.

**QR**

MxM | Matlab(Mac) | Matlab(Linux) | C++(Mac) | C++(iPhone) |
---|---|---|---|---|

121 | .57 | .07 | .0076 | .73 |

961 | 13.72 | 2.46 | 3.26 | 351.83 |

There are some clear shortcomings of Eigen as can be seen with the 351sec processing time on the iPhone. Having implemented QR by hand once I can attest that it is not the easiest thing to do, even if doing the text book method. There is clearly something fishy about Eigen’s implementation for it should technically be as fast Matlab (addition and multiplication times being proof of that).

It was in this last part that my project becomeÂ unfeasibleÂ to be done on the iPhone. Although most of the math I needed was lightening fast, QR and those functions that depend on it became too torturous to be run and waited upon. Stay tuned to how the same platforms perform when doing quadrangulations!