Last year, I got interested in the topic of compile-time programming in C++ and in December I published the format library at github.com/dmeister/pformat. It is clear to me that the library is not and likely never will be production-ready. It was an experiment to see if compile-time string format checking is possible. In fact, it is possible and has been done many times before. I just didn’t know that. Similar things have been done by fmt or pmark/format.

On the other hand, the library didn’t appear to be completely off the mark and it is small enough to explain in 30 minutes or so. So, Pure Prague asked me to give a presentation about it and here we go.

Long story short, last Tuesday, I gave a public presentation for our Prague office about compile-time programming in C++. I used the pformat library as an example and showed constexpr functions, if constexpr and template-meta programming and how they are used in the library.

After the talk, there were pointed questions by a knowledgeable person (“knowledgeable” is a grave understatement, but I am not sure if the person asking would like to see their name mentioned in this blog post) about the compile-time impact. Before, I was quite cavalier about it. The compile times at Pure are quite high and the problem is solved with hardware. Our build system “pb” is backed by a significant compilation cluster, so I mostly forget about it.

However, the point is taken. I should do better, especially before giving presentations about the topic. The library is certainly not optimized for it. Saying that it overuses template meta programming is fair. So, first things first: how bad is it?

Here are the results when pformat is added to the bloat-test of fmtlib (Github fork) on my 1.1 GHz Dual-Core Intel Core m3 Macbook:

MethodCompile Time, sExecutable size, KiBStripped size, KiB
printf5.33330
printf+string47.63330
IOStreams95.16359
fmt74.9133114
compiled_fmt66.0133114
tinyformat136.3113105
Boost Format353.5230200
Folly Format380.410390
stb_sprintf6.96258
pformat130.08278

The pformat library has very high compilation times. The test builds 100 translation units, each printing 5 formats with a mix of integers and strings with 1 to 5 parameters each. That is not a lot of functionality. The compilation times of some other libraries are surprisingly high, too.

So, it is clear: Reducing compilation times of pformat is the next task. There is still a lot to learn and understand the tradeoffs.