Implementing file reading in C/Python
Johannes Bauer
dfnsonfsduifb at gmx.de
Fri Jan 9 00:13:26 EST 2009
James Mills schrieb:
> I have tested this against a randomly generated
> file from /dev/urandom (10M). Yes the Python
> one is much slower, but I believe it's bebcause
> the Python implementation is _correct_ where
> teh C one is _wrong_ :)
>
> The resulting test.bin.pgm from python is exactly
> 3.5M (from 10M). The resulting test.bin.pgm from
> the C version is 16K.
>
> Something is not quite right here :)
Uhh, yes, you're right there... I must admit that I was too lazy to
include all the stat headers and to a proper st_size check in the C
version (just a quick hack), so it's practically hardcoded.
With files of exactly 2GB in size the results should be the same (more
or less, +- 1 line doesn't matter really), because 2 GB / 2048 (the
buffer) = 1 Million.
Sorry I didn't mention that, it was really kind of sloppy,
quick-and-dirty C writing on my part. But you're right, the Python
implementation does what is actually supposed to happen.
Kind regards,
Johannes
--
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
-- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
<48d8bf1d$0$7510$5402220f at news.sunrise.ch>
More information about the Python-list
mailing list