Implementing file reading in C/Python

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Fri Jan 9 12:13:03 EST 2009


Johannes Bauer, I was about to start writing a faster version. I think
with some care and Psyco you can go about as 5 times slower than C or
something like that.

To do that you need to use almost the same code for the C version,
with a list of 256 ints for the frequencies, not using max() but a
manual loop, not using itertools or generators, maybe splitting code
in two functions to allow Psyco to optimize better, maybe using
another array("...") for the frequences too. The data can be read into
an array.array("B"), and so on.

But I think all this work is a waste of time. I like Python, but that
C code, after some cleaning and polishing looks fine for this job. Of
course there are other languages that may give you a little nicer code
for this program, like D, and there may be ways to use numpy too to
speed up the computation of the mode, but they don't look so much
important this time.

Bye,
bearophile



More information about the Python-list mailing list