User Tools

Site Tools


python3:input

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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:output|related sections] we will focus on standard (console) input because its us is typical of most programming contests.+In this and [[python3:output|related sections]] we will focus on standard (console) input because its us is typical of most programming contests.
  
 ===== Input Basics ===== ===== Input Basics =====
Line 35: Line 35:
 >>> x = list(map(float, input().split())) >>> x = list(map(float, input().split()))
 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]
-</code> 
- 
-===== Output Basics ===== 
-Output is handled with the ''%%print()%%'' function. 
- 
-<code python> 
->>> print() # '\n' 
-</code> 
- 
-<code python> 
->>> print("Hello World!") # "Hello World!\n" 
-</code> 
- 
-<code python> 
->>> print("Hello", "World!") # "Hello World!\n" 
-</code> 
- 
-<code python> 
->>> print(1, 2, 3, sep='') # "123\n" 
-</code> 
- 
-<code python> 
->>> print(1, 2, 3, end='-') 
->>> print("a b c") # "1 2 3-a b c\n" 
 </code> </code>
  
Line 89: Line 65:
  
  
-==== Benchmarks ==== +===== Benchmarks ===== 
-The following benchmarks demonstrate the increased likelihood of failure of ''input()'' as input sizes increase. All files used for testing can be found [[files:python3:io_tests|here]].+The following benchmarks demonstrate the increased likelihood of failure of ''input()'' as input sizes increase. All files used for testing can be found [[files:python3:input_tests|here]]
 + 
 +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.)) per line (//n//= number of lines):
 | //n//          | input() | sys.stdin.readline() | sys.stdin.readlines() | | //n//          | input() | sys.stdin.readline() | sys.stdin.readlines() |
 | 10<sup>4</sup> | .034s    | .016s                 | .018s                  | | 10<sup>4</sup> | .034s    | .016s                 | .018s                  |
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.)) per line (//n//= number of lines):
 | //n//          | input() | sys.stdin.readline() | sys.stdin.readlines() | | //n//          | input() | sys.stdin.readline() | sys.stdin.readlines() |
 | 10<sup>4</sup> | .046s    | .037s                 | .033s                  | | 10<sup>4</sup> | .046s    | .037s                 | .033s                  |
python3/input.1534348027.txt.gz · Last modified: 2018/08/15 10:47 by jguerin