GDC vs dmd speed
Paul Jurczak
pauljurczak at yahoo.com
Tue Oct 15 01:20:30 PDT 2013
On Monday, 14 October 2013 at 19:24:27 UTC, Spacen Jasset wrote:
> Hello,
>
> Whilst porting some C++ code I have discovered that the
> compiled output from the gdc compiler seems to be 47% quicker
> than the dmd compiler.
....
Here is a few more data points for microbenchmarks of simple
functions (Project Euler), which supports an observation
(disclaimer: my microbenchmark is not a guarantee of your code
performance, etc.) that the fastest code is produced by LDC, then
GDC and DMD is the slowest one.
Tested on Xubuntu 13.04 64-bit Core i5 3450S 2.8GHz.
--------------------
Test 1:
// 454ns LDC 0.11.0: ldmd2 -m64 -O -noboundscheck -inline
-release
// 830ns GDC 4.8.1: gdc -m64 -march=native -fno-bounds-check
-frename-registers -frelease -O3
// 1115ns DMD64 2.063.2: dmd -O -noboundscheck -inline -release
int e28_0(int N = 1002) {
int diagNumber = 1;
int sum = diagNumber;
for (int width = 2; width < N; width += 2)
for (int j = 0; j < 4; ++j) {
diagNumber += width;
sum += diagNumber;
}
return sum;
}
--------------------
Test 2:
// 118ms LDC 0.11.0: ldmd2 -m64 -O -noboundscheck -inline
-release
// 125ms GDC 4.8.1: gdc -m64 -march=native -fno-bounds-check
-frename-registers -frelease -O3
// 161ms DMD64 2.063.2: dmd -O -noboundscheck -inline -release
bool isPalindrome(string s) {return equal(s, s.retro);}
int e4(int N = 1000) {
int nMax = 0;
foreach (uint i; 1..N)
foreach (uint j; i..N)
if (isPalindrome(to!string(i*j)) && i*j > nMax)
nMax = i*j;
return nMax;
}
--------------------
Test 3:
// 585us LDC 0.11.0: ldmd2 -m64 -O -noboundscheck -inline
-release
// 667us GDC 4.8.1: gdc -m64 -march=native -fno-bounds-check
-frename-registers -frelease -O3
// 853us DMD64 2.063.2: dmd -O -noboundscheck -inline -release
int e67_0(string fileName = r"C:\Euler\data\e67.txt") {
// Read triangle numbers from file.
int[][] cell;
foreach (line; splitLines(cast(char[]) read(fileName))) {
int[] row;
foreach (token; std.array.splitter(line))
row ~= [to!int(token)];
cell ~= row;
}
// Compute maximum value partial paths ending at each cell.
foreach (y; 1..cell.length) {
cell[y][0] += cell[y-1][0];
foreach (x; 1..y)
cell[y][x] += max(cell[y-1][x-1], cell[y-1][x]);
cell[y][y] += cell[y-1][y-1];
}
// Return the maximum value terminal path.
return cell[$-1].reduce!max;
}
--------------------
Here is the relative to LDC code speed averaged over these three
test (larger number is slower):
LDC 1.00
GDC 1.34
DMD 1.76
More information about the Digitalmars-d
mailing list