I'd like to replicate Casey's automatic performance counters in zig https://www.youtube.com/watch?v=uHSLHvWFkto&t=3477s.
However, the process requires generating unique comptime ids , such that when the code hits a counter, the counter is able to find itself in an array of counters, so it can update hits, time spent etc. In C/C++ this is achievable using some pre-processor magic.
There are 2 parts to my question,
- is it possible to generate a comptime counter in zig. It seems like no. I've tried this https://ziggit.dev/t/c-c-macro-challenge-1-boost-pp-counter/2235 but it no longer works - I believe because of changes in the compiler.
- Are there alternative ways to do simple performance measurements? What's nice about Casey's approach is that there's minimal overhead.
Thanks in advance
Day 177 of coding on Handmade Hero. See http://handmadehero.org for details.
This is the first of a hopefully long series of threads where we’ll take some C/C++ macros used by real application and try to find the equivalent (or perhaps better) solution using Zig. The aim is not to replicate the exact behavior of the C code. Generally that’s not possible. The preprocessor just works differently. The aim is to solve th...