stdio performance in tango, stdlib, and perl

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Wed Mar 21 16:16:59 PDT 2007


Walter Bright wrote:
> kris wrote:
>> c) on Linux, tango.io uses the c-lib posix.read/write functions. Is 
>> that what phobos uses also? (on Win32, Tango uses direct Win32 calls 
>> instead)
> 
> Here's the new std.stdio work in progress (doesn't yet include write()). 
> Free free to leverage it as you see fit for Tango.
> Some features of note:
> 1) It peeks under the hood of C's stdio implementation, meaning it's 
> customized for Digital Mars' stdio, and gcc's stdio.
> 2) It throws on I/O errors.
> 3) Unlike C's stdio, it can handle streams of either wide or regular chars.
> 4) It does not go as far as directly using Posix read/write functions or 
> Windows API functions. We wished to avoid that in the interests of 
> interoperability with C's stdio.
> 5) It is fully interoperable with, and is synced with, C's stdio.
> 6) Note how nicely scope(exit) makes the code more readable!

snip]
> private
> void writefx(FILE* fp, TypeInfo[] arguments, void* argptr, int 
> newline=false)
[snip]

Oh, I meant to say that a while ago: some experiments I've done show 
that doing formatting with templates and direct calls is significantly 
faster than the way writefx does it (with a delegate). Probably that 
should be changed. writefln is still very slow. Changing the loop to:

void main() {
   char[] line;
   while (readln(line)) {
     writef("%s", line);
   }
}

yields:

17.8s		dcat

Fortunately, up-and-coming template features will allow the library to 
detect statically known format strings and parse them to render the most 
efficient writing method. And reading, too. I already have a prototype 
readfln function that statically figures out the correctness of its 
format string.


Andrei



More information about the Digitalmars-d mailing list