This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
python3:output [2018/08/15 10:57] jguerin Started removing references to input(). |
python3:output [2018/08/15 16:33] (current) jguerin Added byte count output to shell examples, removed and condensed associated descriptions. |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Output in Python3 ====== | ====== Output in Python3 ====== | ||
There is no magic bullet that leads to the fastest input and output in a programming contest. Having said this, there are typically multiple ways of performing and processing input and output in Python3. By understanding the options that are available and how to optimize them (e.g., conducting tests) you can see a real world performance increase, in particular when faced with high volumes of reads and writes. | There is no magic bullet that leads to the fastest input and output in a programming contest. Having said this, there are typically multiple ways of performing and processing input and output in Python3. By understanding the options that are available and how to optimize them (e.g., conducting tests) you can see a real world performance increase, in particular when faced with high volumes of reads and writes. | ||
+ | |||
+ | Unlike [[python3: | ||
+ | |||
+ | Otherwise, fine tuning of algorithm implementations and input or the selection of C++ may be better choices than fine tuning '' | ||
===== Output Basics ===== | ===== Output Basics ===== | ||
Line 28: | Line 32: | ||
===== Advanced Output ===== | ===== Advanced Output ===== | ||
+ | <code python> | ||
+ | >>> | ||
+ | >>> | ||
+ | |||
+ | 1 | ||
+ | </ | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code python> | ||
+ | >>> | ||
+ | >>> | ||
+ | Hello World! | ||
+ | 13 | ||
+ | </ | ||
+ | |||
+ | Unlike '' | ||
==== Benchmarks ==== | ==== Benchmarks ==== | ||
- | The following benchmarks demonstrate the increased likelihood of failure of '' | + | The following benchmarks demonstrate the increased likelihood of failure of '' |
10 characters per line (//n//= number of lines): | 10 characters per line (//n//= number of lines): | ||
- | | //n// | input() | sys.stdin.readline() | sys.stdin.readlines() | | + | | //n// | print() | sys.stdout.write() | |
- | | 10< | + | | 10< |
- | | 10< | + | | 10< |
- | | 10< | + | | 10< |
1000 characters per line (//n//= number of lines): | 1000 characters per line (//n//= number of lines): | ||
- | | //n// | input() | sys.stdin.readline() | sys.stdin.readlines() | | + | | //n// | print() | sys.stdout.write() | |
- | | 10< | + | | 10< |
- | | 10< | + | | 10< |
- | | 10< | + | |
- | )) | | + | |
- | + | ||
- | The above tests were designed to showcase minimal reading functionality other than temporary storage.((We deliberately avoided additional processing such as typecasts, '' | + | |
+ | The above tests were designed to showcase minimal printing functionality on data that is currently residing in memory. | ||