On Wednesday, 5 June 2013 at 21:15:06 UTC, Jonathan M Davis wrote:
And since it's an example, it makes even less sense.

Not if you want to show off D's compile speed! On my box, compiling Walter's module with -c took:

~$ time dmd -c compress

real    0m0.032s
user    0m0.023s
sys     0m0.007s

3 hundredths of a second. (Running it over and over again gives ranges from .02 to .04).


Now if I add "import std.stdio;" to the bottom of the file, no other changes, not even using it, look at this:

$  time dmd -c compress

real    0m0.456s
user    0m0.407s
sys     0m0.041s

Over 10x as much compile time!



I used to think dmd2 broke something dmd1 got right. Every program I ever did in D1 compiled virtually instantly. A lot of times I'd hit "make" and think nothing happened because it returned so fast. Even my biggest D1 program, a 15k line little RTS game, compiles faster than the typical D2 hello world.


But I've come to see it isn't dmd2 that's slow. It is phobos2.

Compile and link time for my minimal D toy:

$ time make
dmd -version=withoaut_custom_runtime_reflection -debug=allocations -m64 -debug -c object.d minimal.d invariant.d memory.d -gc -defaultlib= -debuglib= gcc minimal.o object.o invariant.o memory.o -o minimal -g -m64 -nostdlib

real    0m0.280s
user    0m0.240s
sys     0m0.032s

That's D2 code but no phobos. Comparable speed to D1.... and still less than an *empty* D2 file that just imports std.stdio! (0.6s to compile and run, over twice as long.)


Now, granted, this can become negligible in bigger programs. It takes about 8 seconds for my work website to compile on my computer. Most that time is spent on my web.d's template magic.

But still, if we want to show off D's compilation speed in examples, that's a good reason to avoid import std.stdio. It is the difference between noticing and not noticing the compile.

Reply via email to