4 ms·
It's a static initialization time FizzBuzz. In this case, I think it's executed before main() is called, and not at compile time. Unless, of course, you have a
by vardump 4y ago
It's a static initialization time FizzBuzz. In this case, I think it's executed before main() is called, and not at compile time.
Unless, of course, you have a very clever compiler that determines memory allocation is not actually allocating anything and that the output is a static string, and there are no side effects. Such a clever compiler could optimize it all into just one "puts" call.
- jessermeyer 4y agoNeither GCC nor Clang bake the final string into the data segment. If I had to guess, printf is the one preventing the more fancy optimizations to take place.
- vardump 4y agoI think so too. Also, depending on stdlib output buffering, the external I/O behavior of 100 puts calls is potentially different from just one call. In other words, there might be a different number of stdout write-calls.