Python(2.5) reads an input file FASTER than pure C(Mingw)

n00m n00m at narod.ru
Sun Apr 27 15:14:17 EDT 2008



Lie wrote:
> On Apr 27, 6:28�am, n00m <n... at narod.ru> wrote:
> > No so simple, guys.
> > E.g., I can't solve (in Python) this:http://www.spoj.pl/problems/INTEST/
> > Keep getting TLE (time limit exceeded). Any ideas? After all, it's
> > weekend.
> >
> > 450. Enormous Input Test
> > Problem code: INTEST
> >
> > The purpose of this problem is to verify whether the method you are
> > using to read input data is sufficiently fast to handle problems
> > branded with the enormous Input/Output warning. You are expected to be
> > able to process at least 2.5MB of input data per second at runtime.
> >
> > Input
> > The input begins with two positive integers n k (n, k<=107). The next
> > n lines of input contain one positive integer ti, not greater than
> > 109, each.
> >
> > Output
> > Write a single integer to output, denoting how many integers ti are
> > divisible by k.
> >
> > Example
> > Input:
> > 7 3
> > 1
> > 51
> > 966369
> > 7
> > 9
> > 999996
> > 11
> >
> > Output:
> > 4
>
> The problem is faulty.
> First, the bottleneck on reading a huge input is the harddisk speed
> and the string processing, the result of the competition doesn't prove
> anything but how fast the string processor and the harddisk is.
> Python's string processing is not a very fast one as it creates a copy
> of the string every now and then.

In case you didn't pay attention:
Python and C++ were tested on the same PC.



More information about the Python-list mailing list