digitalmars.D.learn - newb question re. reading lines from stdin
- "aylwyn" <as6 sanger.ac.uk> Apr 25 2012
- Dmitry Olshansky <dmitry.olsh gmail.com> Apr 25 2012
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? (using DMD64 D Compiler v2.058.)
Apr 25 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
Apr 25 2012








Dmitry Olshansky <dmitry.olsh gmail.com>