C faults, etc
Steven Schveighoffer
schveiguy at yahoo.com
Tue Jul 21 05:56:32 PDT 2009
On Mon, 20 Jul 2009 20:41:03 -0400, Walter Bright
<newshound1 at digitalmars.com> wrote:
> bearophile wrote:
>> Then we have to work on the efficiency of its implementation :-) (See
>> my timings lower in this thread).
>
> I've implemented printf. There is nothing fundamental about its
> efficiency that would be any better than writefln. If writefln is
> slower, it's due to a bug, not anything fundamental.
Part of it could be fundamental.
* D deals with UTF, whereas printf does not
* Phobos calls the C runtime, so it's guaranteed never to beat printf,
since printf is not type-safe, and therefore does less.
* Both Tango and Phobos output functions make use of delegates to output
data. In the case of Phobos, it uses a delegate to call the C runtime's
"delegate" fputc, so it's going to be double the delegate penalty for each
character.
If you're measuring the performance of millions of writes, then you will
see even a slight difference.
Bearophile,
You may want to develop a more specialized function to do file output if
you are writing such large quantities of uniform data, calling the system
calls directly, it might even beat printf.
-Steve
More information about the Digitalmars-d
mailing list