Eigen, GLM and CML: Math Lib Performance on iOS

At the moment I’m playing around with writing a cross platform game library, because that’s what all the cool kids are doing. One of the parts I’m not particularly looking forward to is writing a math library for the rendering. Fortunately, far greater programmers than I have done so already. In fact, many greater programmers have. Three seem quite popular: CML, Eigen and GLM.

Being lazy I searched around to find out which one seemed fastest or easiest to use with mobile, and I found a very useful post on the three common ones at http://www.mfoot.com/2012/01/choosing-a-maths-library-for-cross-platform-c-game-development/. Unfortunately, the tests had been run only on desktop and Android, so I’ve forked the repository and added an iOS runner for the tests. You can find it at:

I also added a branch with the current latest source code for each of the libraries:

A full description of the tests can be seen in the source code, or you can read through the original article by Martin.

Here are the results for running it on my iPhone 4 with the original library versions:

                        iOS release build
Eigen additions         2515
Eigen multiplications   6915

GLM additions           3549
GLM multiplications     7347

CML additions           3004
CML multiplications     11511

(Timings in milliseconds. Smaller is better.)

And once more with the latest library versions:

                        iOS release build
Eigen additions         2161
Eigen multiplications   6721

GLM additions           3340
GLM multiplications     5865

CML additions           2964
CML multiplications     11112

(Timings in milliseconds. Smaller is better.)

I haven’t fiddled with compile settings beyond using a release build, so it’s quite likely the performance can be improved.

The results for the CML multiplications are suspiciously slow, so I wonder if something odd is going on there, but overall it seems to come down to Eigen or GLM.

I think, for the moment, I’ll use GLM for a couple of reasons: it’s geared towards OpenGL use rather than being a generic linear algebra library, and it has more straightforward MIT licensing.