C faults, etc

bearophile bearophileHUGS at lycos.com
Mon Jul 20 10:15:50 PDT 2009


Daniel Keep:
>Why on earth should the D compiler special-case a function that's not even supposed to be used?!<

What's the purpose of being able to use the C std lib in D programs if then such functions aren't supposed to be used?


> Actually, let's check... (Goes off to test.)<

This is a first little test, with DMD V.2.031, on Windows, Phobos2:

import std.stdio: printf;
void main() {
    const int N = 2_000_000;
    for (int i; i < N; i++)
        printf("test %d\n", i);
}


A second version that uses writefln:

import std.stdio: writefln;
void main() {
    const int N = 2_000_000;
    for (int i; i < N; i++)
        writefln("test %d", i);
}

I have redirected their output to a file (26.2 MB file).
The timings are: 1.16 seconds for the version with printf, and 14.93 seconds for the version with writefln.

-----------------------

BCS:
>It would be interesting to write a template that takes a static format string (using writef syntax) and, based on its argument tuple to generates a trivial wrapper around printf with a guarantied correct (printf syntax) format string.<

A nice idea, thanks. I may do that.

Bye,
bearophile



More information about the Digitalmars-d mailing list