I would not expect any lasting performance differences between these approaches.
The advantage of the first approach is that any reasonably correct code you rely on (the modules you import) will automatically pick up your desired redirection.
The second approach has no advantage. It is only suitable for debugging or discarding code ... and not even a good idea for that. You want your exit decisions to be grouped into several clearly defined places, rather than scattered across your code every time you call print() . In Python3, print() has a function, not an operator. This allows you to override it if you want. So you can def print(*args) if you want. You can also call __builtins__.print() if you need access to it, for example, in the definition of your own print() .
The third approach ... and, as a rule, the principle that all of your output should be generated in certain functions and class methods that you define for this purpose ... is probably best.
You should separate your output and formatting from the main functionality as much as possible. Keeping them separate allows you to use the kernel. (For example, you can start with something that was intended to be run from the text / shell console, and later you need to provide a web interface, a full-screen (damned) interface or a graphical interface for it. You can also create completely different functions around it. .. in situations where the resulting data should be returned in its native form (as objects), and not be inserted as text (output) and re-processed into new objects.
For example, I had several cases when I wrote several complex queries and collected data from different sources and printed a report ... say about inconsistencies ... later you need to adapt to a form that could spit out data in some form (for example, YAML / JSON), which can be transferred to some other system (for example, to coordinate one data source with another.
If from the very beginning you save the basic operations separately from the output and formatting, then such an adaptation is relatively simple. Otherwise, this entails quite a lot of refactoring (sometimes equivalent to a complete rewrite).
Jim dennis
source share