stdio line-streaming revisited

kris foo at bar.com
Wed Mar 28 20:23:09 PDT 2007


Andrei Alexandrescu (See Website For Email) wrote:
> kris wrote:
> 
>> Last week there were a series of posts regarding some optimized code 
>> within phobos streams. A question posed was, without those same 
>> optimizations, would tango.io be slower than the improved phobos [1]
>>
>> As these new phobos IO functions are now available, Andrei's 
>> "benchmark" [2] was run on both Win32 and linux to see where tango.io 
>> could use some improvement.
> 
> [snip]
> 
> On my machine, Tango does 4.3 seconds and the following phobos program 
> (with Walter's readln) does 5.4 seconds:

On Win32, the difference is very much larger. As noted before, several 
times faster. Those benefits will likely translate to linux going forward.

> 
> #!/usr/bin/env rundmd
> import std.stdio;
> 
> void main() {
>   char[] line;
>   while (readln(line)) {
>     write(line);
>   }
> }
> 
> where write is a function that isn't yet in phobos, of the following 
> implementation:
> 
> size_t write(char[] s) {
>   return fwrite(s.ptr, 1, s.length, stdout);
> }

Wondered where that had gone


> 
> Also, the Tango version has a bug. Running Tango's cat without any pipes 
> does not read lines from the console and outputs them one by one, as it 
> should; instead, it reads many lines and buffers them internally, 
> echoing them only after the user has pressed end-of-file (^D on Linux), 
> or possibly after the user has entered a large amount of data (I didn't 
> have the patience). The system cat program and the phobos implementation 
> correctly process each line as it was entered.

If you mean something that you've written, that could presumeably be 
rectified by adding the isatty() test Walter had mentioned before. That 
has not been added to tango.io since (a) it would likely make programs 
behave differently depending on whether they were redirected or not. 
It's not yet clear whether that is an appropriate specialization, as 
default behaviour, and (b) there has been no ticket issued for it

Again, please submit a ticket so we don't forget about that detail. We'd 
be interested to hear if folk think the "isatty() test" should be 
default behaviour, or would perhaps lead to corner-case issues instead




More information about the Digitalmars-d mailing list