speed up python I/O ??

I’m using python 2.7, i keep getting TLE when input can take very high values (10^5 say).Its given that we need to include these lines to speed up I/O

import psyco
psyco.full()

but the psyco page at sourceforge.net says its not supported for 2.7 version.
They have a link to pypy.org, so is this supported on codechef?
Is there any other way to speed up program execution on python?

Please help…

1 Like

I tried many times submitting with and without the ‘import psyco’ on questions requiring large inputs and the truth is it’s >.> slower.

using the input technique below is just a bit faster than normal ‘raw_input()’ ~I wouldn’t worry too much on I/O with python

import sys
sys.stdin.readline()

you can see a difference if you try it on http://www.codechef.com/problems/INTEST

Reading whole input at once will make it better.

import sys

all = sys.stdin.readlines()

Now all is a list of complete inputs
To iterate over all elements you can use

for n in all
do something

Try it with pyt 2.7 on Enormous Input Test problem here - http://www.codechef.com/problems/INTEST

Reading each line at once resulted AC in 34sec

This method got AC in 21sec

P.S : I am new to python (Dont mind if I am wrong) :slight_smile:

3 Likes

Typo

for n in all:

    //do something

nice,nice, I’ll be sure to use this on questions with large inputs ^^

//