This question came up on reddit yesterday, since many projects have been porting their build system to Meson (most of them from autotools, some from CMake). Someone said that Meson provides supposedly faster build times than CMake and I was quite surprised to hear that. So I decided to test on my own.

I used libqmatrixclient as test project, since it’s not a trivial hello-world app yet not the most complex project ever. It builds a C++ (static) library and a little example app that links to that library.

libqmatrixclient uses CMake, but I stripped down its CMakeLists.txt just to be sure to compare a minimal CMake configuration with a minimal Meson configuration. The test has been performed with the ninja backend.

What I found out is that Meson’s build time is actually higher than CMake’s. I cannot claim this is true in general, but it surely shows that Meson is not perfect and probably not “faster” than CMake, in general.

Configuration times

The elapsed time of the configuration step is not really relevant, since you usually run it only once. But anyway here we go:

$ time cmake -GNinja -DCMAKE_BUILD_TYPE=Debug ..
real    0m1,337s
user    0m1,078s
sys     0m0,266s

while with Meson:

$ time meson meson-build
real    0m0,380s
user    0m0,295s
sys     0m0,103s

According to this first test, Meson is faster than CMake to configure the demo project. For the record, CMake generates a 435 LOC build.ninja file, while Meson’s build.ninja is only 289 LOC. At the end of the configuration step, there are 21 files in the CMake build folder and 10 files in the Meson build folder. CMake also generates a rules.ninja file (83 LOC) that is included in build.ninja, while Meson doesn’t.

Again, I don’t think the configuration step is that relevant, so let’s move on to what actually matters: build times.

Build times

This is where CMake performs better than Meson. When I run ninja from the CMake build folder I get:

$ time ninja
real    0m17,781s
user    0m58,066s
sys     0m3,211s

If I run ninja from the Meson build folder instead:

$ time ninja
real    0m20,326s
user    1m14,125s
sys     0m3,801s

In both cases we built a static library and a simple executable linking to that library. In both cases we performed a debug build. Despite CMake having a bigger build.ninja, the CMake build takes 2 seconds less than the Meson build (13.3% faster). Not negligible, in my opinion.

I don’t know why this happens, my best guess is that CMake has a better ninja generator (which would make sense since CMake is older).

While it is probably true that Meson is “faster” than autotools, this simple experiment shows that we probably cannot say the same with CMake (or modern CMake, at least).