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:49]
jguerin Bumped up header of Advanced Input.
python3:input [2018/08/15 16:40] (current)
kericson [Benchmarks] - moving from io_tests to input_tests
Line 37: Line 37:
 </code> </code>
  
-===== Output Basics ===== +===== Advanced Input =====
-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> +
- +
-====== Advanced Input ======+
 ''input()'' will scale well for many easy and mid-level contest problems. For mid to upper problems with significant bounds on reads and writes ''input()'' will carry an increased risk of //time limit exceeded// judgements.((There is no guaranteed cutoff, but for many problems ''input()'' is //increasingly likely// to fail around 10<sup>3</sup>≤//n//≤10<sup>4</sup> lines.)) ''input()'' will scale well for many easy and mid-level contest problems. For mid to upper problems with significant bounds on reads and writes ''input()'' will carry an increased risk of //time limit exceeded// judgements.((There is no guaranteed cutoff, but for many problems ''input()'' is //increasingly likely// to fail around 10<sup>3</sup>≤//n//≤10<sup>4</sup> lines.))
  
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.1534348166.txt.gz · Last modified: 2018/08/15 10:49 by jguerin