DMD is faster than LDC and GDC

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Thu Nov 12 10:36:51 PST 2015


On 11/12/15 13:22, Daniel Kozak via Digitalmars-d wrote:
>>> timings:
>>> > >
>>> > > DMD (-O -release -inline -boundscheck=off):
>>> > > real	0m0.003s
>>> > > user	0m0.000s
>>> > > sys	0m0.000s
>>> > >
>>> > > LDMD2-ldc2 (-O -release -inline -boundscheck=off):
>>> > > real	0m1.071s
>>> > > user	0m1.067s
>>> > > sys	0m0.000s
>>> > >
>>> > >
>>> > > GDC (-O3 -finline -frelease -fno-bounds-check):
>>> > > real	0m0.724s
>>> > > user	0m0.720s
>>> > > sys	0m0.003s  
>> > 
>> > What versions of these compilers? I suspect the majority (maybe 
>> > 80%-ish) of the time is spent allocating memory, so you might be 
>> > seeing GC improvements in recent DMD
> DMD 2.069
> 
> LDC 2.067
> 
> GDC 2.065
> 
> No it is not cause by memory allocations.
> 
> It seems DMD can recognize that fmttable has same result every time, so
> it does compute it only once.

Comparisons using different frontend versions are very unfair -
- *every D release introduces a new language dialect* (for example:
http://dlang.org/changelog/2.068.0.html#attribinference3).

Out of curiosity, how does this slightly more sane version perform?
(I don't have any dmd or ldc compilers; it takes ~80ms using GDC)

   import std.stdio;

   auto fmttable(alias sink=sink)(immutable(string[][]) table) {
       import std.range : take, repeat;

       if (table.length == 0) return;
       // column widths
       auto widths = new int[](table[0].length);

       foreach (rownum, row; table) {
           foreach (colnum, cell; row) {
               if (cell.length > widths[colnum])
                   widths[colnum] = cast(int)cell.length;
           }
       }

       foreach (row; table) {
           sink("|");
           foreach (colnum, cell; row) {
               sink(cell, ' '.repeat().take(widths[colnum]-cast(int)cell.length), "|");
           }
           sink("\n");
       }
   }

   void sink(S...)(S s) {
      foreach(I, _; S)
         write(s[I]);
   }

   void sink0(S...)(S s) {}

   void main() {
       immutable table = [
           ["row1.1", "row1.2  ", "row1.3"],
           ["row2.1", "row2.2", "row2.3"],
           ["row3.1", "row3.2", "row3.3  "],
           ["row4.1", "row4.2", "row4.3"],
           ["row5.1", "row5.2", "row5.3"],
       ];

       fmttable(table);
       int i;
       for (i=0; i < 1000000; ++i) {
           fmttable!sink0(table);
       }
       sink(i, "\n");
   }


artur


More information about the Digitalmars-d mailing list