yosupo's blog

By yosupo, history, 7 years ago, In English

Recently, I start to use dlang in competitive programming. There are 3 dlang compiler, "DMD", "LDC", "GDC".

In competitive programming, best choice is "LDC", but in many online judge, we can use only "DMD" or "GDC".

I hope to many online judge install "LDC", so I write this blog.

Compiler compare

  • DMD : Official compiler. Can use latest language version. Moderate Fast.
  • LDC : based on llvm. Moderate new. Very Fast.
  • GDC : based on gcc. Not new, Moderate Fast.

How to install ldc

  1. Go to github's release page https://github.com/ldc-developers/ldc/releases
  2. Download ldc(If you use 64bit-linux, ldc2-1.2.0-linux-x86_64.tar.xz, in now)
  3. Extract
  4. ADD /your/download/path/ldc2-1.2.0-linux-x86_64/bin to $PATH.

How to use ldc

  • Debug mode : ldc2 -d-debug A.d

  • Release mode(and optimize) : ldc2 -O -release A.d

  • Vote: I like it
  • +25
  • Vote: I do not like it

| Write comment?
»
7 years ago, # |
  Vote: I like it +10 Vote: I do not like it

LDC is indeed nice, it's almost bleeding edge in terms of language features, and makes fast executables. The main advantage of DMD is that it compiles fast, which matters when compiling locally. On the other hand, the compiled executable may perform sub-optimally compared to when using LLVM and GCC backends.

Anyway, in my experience at setting and participating in programming contests, D compiled with DMD almost always performs between C++/GCC and Java if we look at similar solutions in these languages. And since the time limit is usually at least 2x Java time, DMD is a viable, if not the most optimal, choice.

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Since I mainly use DMD, my command lines differ:

(release) dmd -O -release -inline -boundscheck=off

(debug) dmd -g -debug -unittest

Here, -debug is useful for debug output. The following program can be debugged locally and then submitted without any changes:

    auto a = readln.split; // read a line and split by whitespace
    debug {writeln (a);} // print the array of strings, but only in debug builds

And -g keeps the stack trace meaningful when something goes wrong.

On Windows, I have to add -L/STACK:268435456 to have enough stack available, similar to mingw/gcc.

Also, there's ldmd2 executable in LDC which accepts options in the same form as dmd and provides an easy DMD-to-LDC transition.

  • »
    »
    7 years ago, # ^ |
      Vote: I like it +10 Vote: I do not like it

    I edited ldc's debug version flag, thanks :) I use stupid debug in usually(comment out all debug writeln before submit). I would use debug{} in future.

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by yosupo (previous revision, new revision, compare).

»
6 years ago, # |
  Vote: I like it +16 Vote: I do not like it

On SPOJ LDC2-1.1.0 is a little bit slower than DMD-2.072 (for several problems and same code I got TL for LDC2 and AC for DMD). It is very strange, because when I installed same versions of both compilers at home computer, sources compiled by LDC2 are executed about 1.5 times faster than compiled by DMD.

»
6 years ago, # |
  Vote: I like it +16 Vote: I do not like it

Recently, I start to use dlang in competitive programming

Are you curious to try it or there are some advantages of Dlang over C/C++?