This repository contains some simple tests between different C++ math libraries that I wrote during the process of selecting a math library to use for game development.
At the time of writing, the libraries tested are:
So far I've tested matrix addition and multiplication. src/Main.cpp
contains
code that will generate two lists of 1 million 4x4 float matrices for each
library, populate them with random float values, and then add each one from the
first column to the second. It will then do the same for multiplication. It
will repeat this step 10 times and print out how long it took for each library.
Results for each library vary greatly with architecture and optimisation level.
Mac - 2.3 GHz 8-Core Intel Core i9 - 32 GB RAM
Library | Additions (ns) | Multiplications (ns) |
---|---|---|
Eigen | 4049.47 | 25766.21 |
GLM | 1030.72 | 11677.72 |
CML | 7265.88 | 28132.13 |
GLKit | 187.82 | 394.39 |
Kazmath | 355.63 | 2863.69 |
Bullet | 757.27 | 17074.74 |
simd | 642.00 | 1501.06 |
Mac - 8-Core Apple M1 - 16 GB RAM
Library | Additions (ns) | Multiplications (ns) |
---|---|---|
Eigen | 2522.06 | 7263.56 |
GLM | 773.91 | 5821.86 |
CML | 3793.53 | 10119.19 |
GLKit | 126.91 | 223.10 |
Kazmath | 224.62 | 360.63 |
Bullet | 508.76 | 1411.24 |
simd | 307.25 | 701.55 |
These choices are largely influenced by reading their websites and posts at the Game Development StackExchange site:
- Best C Math Library for Game Engine?
- High Performance Math Library for Vector And Matrix Calculations
- Complete Math Library for use in OpenGL ES 2.0 Game?
My requirements are:
- C++
- Matrix operations
- Vector operations
- Complex number support
- Quarternian operations
- Cross-platform, easy to compile on different platforms with different compilers.
- Fast. SIMD instruction support is preferred.
- Easy to use and understand.
- Permissive license. Accreditation is perfectly fine. Forcing distribution of source code isn't.
This section contains my notes to help understand the design choices and
advantages and disadvantages of each library. It is fairly long so has been
moved to LIBRARIES.md
. This section also contains licensing information for
each library.
- Matrix operations - addition, multiplication
This is for gaming applications. Features that I can think of that need testing are:
- Matrix operations - including addition, subtraction, multiplication, inversion, transposition, translation, rotation, scale
- Vector operations - cross/dot product, normalisation, zeroing, magnitude, length2, scalar operands, normal calculation
- Euler angle + Quarternion operations - rotation, interpolation, conversion, inversion, multiplication
- Coordinate system conversion (Cartesian, spherical)
- Random numbers - generator speed, period, statistical randomness
- Possibly noise generation
- Ease of integration with gl functions like glTranslate()
- Remove Android tests
- Add GLKMath library.
- Add kazmath library.
- Modify the time calculation. Now based on the clock() function.
- Add bullet vectormath library.