I was writing a C++ program, and now I need to benchmark it. For logging I don’t want to use a library, since it is an extra dependency (although spdlog
is great, for example). I am looking for an elegant and short solution to make the logging lines present or not present based on a parameter.
Checking an if statement can be considered an overhead as well. The nicest thing I could come up with is something like:
#include <iostream>
#define DEBUG
int main()
{
#ifdef DEBUG
std::cout << "This is a log message" << std::endl;
#endif // DEBUG
}
Wrapping the ifdef
–endif
in a define is impossible as far as I saw. So is there a better solution? Or a shorter, more elegant one?