Performance penalty for using ranges
Paul Jurczak
pauljurczak at yahoo.com
Sun Aug 25 12:35:01 PDT 2013
On Sunday, 25 August 2013 at 18:07:33 UTC, Paul Jurczak wrote:
[..]
> I'm also running it with LDC, but it reports timings too good
> to be true - something meaningful is getting optimized away and
> I'm trying to find out why.
[..]
It seems that LDC optimizer is smarter than I expected and it was
able to optimize away comparison on constant elements of array a
in my test:
int test(alias F)(int N) {
int a[10];
int n = 0;
foreach (immutable _; 0..N) {
a[4] = !a[4];
n += F(a);
}
return n;
}
I modified it, so there is no constant elements and all cases of
pairwise comparison are exercised:
int test(alias F)(int N) {
enum L = 10;
int a[L];
int n = 0;
foreach (int i; 0..N) {
auto j = (i%L + L/2)%L;
a[j] = !a[j];
n += F(a);
}
return n;
}
Here are the results:
Xubuntu 13.04 64-bit Core i5 3450S 2.8GHz (3.5GHz turbo):
LDC 0.11.0: ldmd2 -m64 -O -noboundscheck -inline -release
100000 5284
100000 4265
100000 4268
100000 5717
100000 4265
GDC 4.8.1: gdc -m64 -march=native -fno-bounds-check
-frename-registers -frelease -O3
100000 4612
100000 5717
100000 5718
100000 4984
100000 11546
DMD64 2.063.2: dmd -O -noboundscheck -inline -release
100000 8350
100000 14615
100000 14597
100000 14270
100000 18509
Windows 7 64-bit Core i5 2500 3.4GHz turbo:
DMD 2.063.2 (32-bit) dmd -O -noboundscheck -inline -release
100000 9803
100000 17050
100000 17031
100000 20851
100000 20283
I'm stunned by LDC ability to optimize isPalindrome4 to the best
performance level of the whole group. Other compilers placed it
at the bottom of performance rank.
More information about the Digitalmars-d
mailing list