stdio performance in tango, stdlib, and perl

kris foo at bar.com
Wed Mar 21 16:58:34 PDT 2007


Andrei Alexandrescu (See Website For Email) wrote:
[snip]

>>> 4.7s    tcat
>>
>>
>> Thanks. If tango.io were to retain CR on readln, then it would come 
>> out ahead of everything else in this particular test
> 
> 
> Well probably but must be tested. Newlines comprise about 3% of the file 
> size.

Yeah, I can imagine. Module tango.io.Console at line 119 should have a 
slice in it ... if you change 'j' to be 'i+1' instead, that should 
remove the chop

Tango should still come out in front, although I have to say that 
benchmarks don't really tell very much in general i.e. doesn't mean much 
of anything important whether tango "wins" this or not (IMO)

Having said that, I'm very glad you ran this since it shows how much 
overhead there is in a flush operation (on *nix) that's very useful to know


> 
>> Can you distill the benefits of retaining CR on a readline, please?
> 
> 
> I am pasting fragments from an email to Walter. He suggested this at a 
> point, and I managed to persuade him to keep the newline in there.
> 
> Essentially it's about information. The naive loop:
> 
> while (readln(line)) {
>   write(line);
> }
> 
> is guaranteed 100% to produce an accurate copy of its input. The version 
> that chops lines looks like:
> 
> while (readln(line)) {
>   writeln(line);
> }
> 
> This may or may not add a newline to the output, possibly creating a 
> file larger by one byte. This is the kind of imprecision that makes the 
> difference between a well-designed API and an almost-good one. Moreover, 
> with the automated chopping it is basically impossible to write a 
> program that exactly reproduces its input because readln essentially 
> loses information.


That's a valid point

[snip]



More information about the Digitalmars-d mailing list