dmd -run speed trends

Siarhei Siamashka siarhei.siamashka at gmail.com
Sun Dec 17 12:52:56 UTC 2023


On Saturday, 16 December 2023 at 23:35:12 UTC, Siarhei Siamashka 
wrote:
> That's what any normal user would see if they compare compilers 
> out of the box in the most straightforward manner without 
> tweaking anything.

Now if we start tweaking things, then it makes sense to use `dub` 
or `dmd -run` instead of `rdmd`, because `rdmd` just wastes 
precious milliseconds for nothing. Then there's shared vs. static 
Phobos and the possibility to use a faster linker (mold). Here's 
another comparison table (with a "printf" variant from 
https://forum.dlang.org/post/pfmgiokvucafwbuldjaj@forum.dlang.org 
added too), all timings are for running the program immediately 
after editing its source:

| test                      | static | shared | static+mold | 
shared+mold |
|---------------------------|--------|--------|-------------|-------------|
| rdmd bench_writefln.d     | 1.21s  | 0.98s  |    1.02s    |    
0.93s    |
| dub bench_writefln.d      | 0.84s  | 0.60s  |    0.63s    |    
0.55s    |
| dmd -run bench_writefln.d | 0.80s  | 0.55s  |    0.60s    |    
0.51s    |
|---------------------------|--------|--------|-------------|-------------|
| rdmd bench_writeln.d      | 0.60s  | 0.38s  |    0.43s    |    
0.34s    |
| dub bench_writeln.d       | 0.50s  | 0.27s  |    0.32s    |    
0.23s    |
| dmd -run bench_writeln.d  | 0.47s  | 0.23s  |    0.28s    |    
0.19s    |
|---------------------------|--------|--------|-------------|-------------|
| rdmd bench_printf.d       | 0.33s  | 0.13s  |    0.18s    |    
0.09s    |
| dub bench_printf.d        | 0.34s  | 0.14s  |    0.19s    |    
0.10s    |
| dmd -run bench_printf.d   | 0.31s  | 0.10s  |    0.15s    |    
0.06s    |

The top left corner represents the current out of the box 
experience (`rdmd` and static Phobos library linked by bfd). The 
bottom right corner represents the potential for improvement 
after tweaking both code and the compiler setup (`dmd -run` and 
shared Phobos library linked by mold). I still don't think that 
the printf variant represents a typical D code, but the other 
writefln/writeln variants are legit. Compare this with the Go 
results (0.15s) from 
https://forum.dlang.org/post/dcggscrhrtxkyqmkljpm@forum.dlang.org

For this test I rebuilt DMD 2.106.0 from sources (make -f 
posix.mak HOST_DMD=ldmd2 ENABLE_RELEASE=1 ENABLE_LTO=1) with the 
mold fix applied and used the LDC 1.32.0 binary release to 
compile it. This was done in order to match the configuration of 
the DMD 2.106.0 binary release as close as possible. If anyone 
wants to reproduce this test too, please don't forget to 
recompile Phobos & druntime because just replacing the DMD binary 
alone is not enough to make mold work.


More information about the Digitalmars-d mailing list