newb question re. reading lines from stdin

Dmitry Olshansky dmitry.olsh at gmail.com
Wed Apr 25 04:16:38 PDT 2012


On 25.04.2012 15:10, aylwyn wrote:
> Hi, I've just written a smallish program reading
> lines from stdin and doing some parsing and other text
> processing. I find it's about 3-4 times faster than a python
> script I had doing the same thing, which is nice but not as good
> as I hoped. After profiling, it seems almost half the total time
> is being spent in
>
> std.stdio.File.ByLine!(char, char).ByLine.popFront()
>
> called once per line on stdin, and within that mostly in
>
> std.stdio.File.readln!(char).readln(ref char[], dchar)
>
>
> Before I do some benchmark comparisons with C etc, can I just
> check that
>
> foreach (line; stdin.byLine())
>
> is the correct way to do this. Are there any lower-level methods
> I could use for buffered access to a stream of chars?

It is. It needs more optimizations though. There have been talks of 
byLineAsync() that will opportunistically fill next line in background 
and so on and so forth.

>
> (using DMD64 D Compiler v2.058.)

I bet straight fgets will beat stdin.byLine.

-- 
Dmitry Olshansky


More information about the Digitalmars-d-learn mailing list