zq7r
(Chris)
1
I use a lot of print statements for various diagnostic reasons while developing. Should I go and comment them all out for a final compiled product that is performance critical?
AlexanderM
(Alexander Momchilov)
2
Like with every performance question: profile it.
"Should I go and comment them all out for a final compiled product" nope. Depending on how many there, that would take a really long time, and in any case would be a waste of your time.
Instead, using a logging framework, that lets you set log levels by class/subsystem/etc. In prod, you can have all higher log levels (e.g. error, warn) be logged, but not lower ones (like info and verbose).
Also more generally, learn to use a debugger, and you'll notice you'll have much less need for copious log statements.
zq7r
(Chris)
3
Perhaps I should not have used the word "diagnostic" as I did not mean to give the impression that I use the "print" statement for debugging. Of course for the purpose of dubugging I use xcode's built in debugger. I use the print statement to report certain milestones as my app launches. In any case my hunch is that any print statements are ignored when producing a binary but I'm not 100% sure. I do take your point about profiling and I will try to do that.
SDGGiesbrecht
(Jeremy David Giesbrecht)
4
print(...) is (primarily) for sending stuff to standard output. This is absolutely necessary even in release builds for command line tools. Nothing will optimize it away. (Even a GUI application can be launched in such a way that the standard output is displayed.)
That is why @AlexanderM advised you to look into using a logging library instead for that sort of thing.
3 Likes