Static local variables are initialised on the first function call:
Variables declared at block scope with the specifier static have static storage duratio
From https://en.cppreference.com/w/cpp/language/initialization
Deferred dynamic initialization
It is implementation-defined whether dynamic initialization happens-before the first statement of the main function (for statics) or the initial function of the thread (for thread-locals), or deferred to happen after.If the initialization of a non-inline variable (since C++17) is deferred to happen after the first statement of main/thread function, it happens before the first odr-use of any variable with static/thread storage duration defined in the same translation unit as the variable to be initialized.
So similar check may have to be done also for global variables.
so f()
is not necessary "slower" than g()
.