stdio line-streaming revisited

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Wed Mar 28 19:46:20 PDT 2007


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:

#!/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);
}

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.

This bug should be fixed for the programs to be comparable. After that, 
it would help giving numbers comparing all of tango, phobos, and cat, 
with the perl baseline.


Andrei



More information about the Digitalmars-d mailing list