This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
python3:input [2018/08/15 10:47] jguerin |
python3:input [2018/08/15 16:40] (current) kericson [Benchmarks] - moving from io_tests to input_tests |
||
---|---|---|---|
Line 4: | Line 4: | ||
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. | 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. | ||
- | In this and [[python3: | + | In this and [[python3: |
===== Input Basics ===== | ===== Input Basics ===== | ||
Line 35: | Line 35: | ||
>>> | >>> | ||
1.2 2.3 3.4 4.5 # x=[1.2, 2.3, 3.4, 4.5] | 1.2 2.3 3.4 4.5 # x=[1.2, 2.3, 3.4, 4.5] | ||
- | </ | ||
- | |||
- | ===== Output Basics ===== | ||
- | Output is handled with the '' | ||
- | |||
- | <code python> | ||
- | >>> | ||
- | </ | ||
- | |||
- | <code python> | ||
- | >>> | ||
- | </ | ||
- | |||
- | <code python> | ||
- | >>> | ||
- | </ | ||
- | |||
- | <code python> | ||
- | >>> | ||
- | </ | ||
- | |||
- | <code python> | ||
- | >>> | ||
- | >>> | ||
</ | </ | ||
Line 89: | Line 65: | ||
- | ==== Benchmarks ==== | + | ===== Benchmarks |
- | The following benchmarks demonstrate the increased likelihood of failure of '' | + | The following benchmarks demonstrate the increased likelihood of failure of '' |
+ | |||
+ | 10 character and 1000 character benchmarks were selected to be indicative of many contest problems, and otherwise should indicate performance under most other assumptions. | ||
- | 10 characters per line (//n//= number of lines): | + | ==== Small Lines ==== |
+ | 10 characters((Selected to be roughly on the order of many similar reads: numeric primitives, small strings, etc.)) | ||
| //n// | input() | sys.stdin.readline() | sys.stdin.readlines() | | | //n// | input() | sys.stdin.readline() | sys.stdin.readlines() | | ||
| 10< | | 10< | ||
Line 99: | Line 78: | ||
- | 1000 characters per line (//n//= number of lines): | + | ==== Large Lines ==== |
+ | 1000 characters((Selected to be roughly on the order of problems with large reads that may be encountered in a contest setting.)) | ||
| //n// | input() | sys.stdin.readline() | sys.stdin.readlines() | | | //n// | input() | sys.stdin.readline() | sys.stdin.readlines() | | ||
| 10< | | 10< |