random k-sample of a file

bearophile bearophileHUGS at lycos.com
Fri Oct 10 05:59:55 PDT 2008


Sergey Gromov:
> While experimenting with Bearophile's loader
> > http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.announce&article_id=13402
> I've found out that BufferedFile is the fastest available way to process 
> a file line-by-line.  So the alternative should be as fast.

BufferedFile seems the faster in Phobos, but it's 2-3 times slower than the line-by-line reading you have in Python, and I think it has 4 bugs, so I don't use it much, that's why I use the xfile() of my libs, that is a little slower, but without those bugs.

Few bugs of BufferedFile can be seen if you try to load a very large file made of a single line (crashes D every time), or you try reading lines with \0 at the end of the line, etc. They are corner cases, usually.

I suggest reading the C sources of the I/O of Python (or Perl, if you are able to read the sources. I think the differences in clarity between Python and Perl can be seen even in their C sources).

Bye,
bearophile



More information about the Digitalmars-d mailing list