I am writing a program for which I need up to 100,000 lines of integer pairs from sys.stdin on which to do calculations. My whole program, consisting of reading this input and performing calculations on the integers of each input line has to take a maximum of 1 second. The problem is that, just going through all the lines of input takes way more than 1 second! In the case of 100,000 lines, it takes roughly 10 seconds. My question is, is this performance to be expected for this amount of lines?
The input is in the format:
100000 5 100000
72324 563
56487 2252
866 19750
65532 69349
96171 56840
70287 14094
76381 14722
48359 38831
74431 12611
29994 66230
92169 20726
39565 38429
59416 2360
45470 40781
...
Where the rightmost integer on the first line indicates the number of lines to come. To read this input, I'm using the following code:
import time
from sys import stdin, stderr
def read():
row = stdin.readline().split()
n, k, q = int(row[0]), int(row[1]), int(row[2])
start = time.clock()
for i in range(q):
line = stdin.readline().split()
# Do some calculation on the integers of this line...
end = time.clock()
print("Reading time: " + str(end-start))
read()
Am I missing something here? The limit of 1 second is due to this being a school project of calculating Q number of distances between two nodes in a K-ary tree. Thanks in advance.