Linked by ebasconp on Fri 10th Jun 2011 22:22 UTC
Benchmarks "Google has released a research paper that suggests C++ is the best-performing programming language in the market. The internet giant implemented a compact algorithm in four languages - C++, Java, Scala and its own programming language Go - and then benchmarked results to find 'factors of difference'."
Permalink for comment 476922
To read all comments associated with this story, please click here.
RE[3]: GCC isn't all that great
by acobar on Sat 11th Jun 2011 09:12 UTC in reply to "RE[2]: GCC isn't all that great"
Member since:

Well, I will repeat to you what I do to everyone I met and that would ask my advise (not your case) on programming: first look for a good, tested, implementation. Many people try to code fragments that are already optimized for ages. They don't look at Donald Knuth's ACP, fftw, lapack, atlas and many other well-thought code before they start and, as such, write subpar code.

For example, if you change your code to:

void vector_add(unsigned int*a, unsigned int a_len, unsigned int*b, unsigned int b_len)
unsigned int i;
for (i = a_len < b_len ? a_len : b_len ; i > 0 ; ) {
a[i] += b[i];

You get a pretty decent optimized code:

cmpl %esi, %ecx
cmovbe %ecx, %esi
testl %esi, %esi
je .L1
.p2align 4,,10
.p2align 3
decl %esi
mov %esi, %eax
movl (%rdx,%rax,4), %ecx
addl %ecx, (%rdi,%rax,4)
testl %esi, %esi
jne .L4

As can be clearly seen, compilers are not black-magic wizards and, regretfully, depend on the code quality we give to them, and we should never forget that.

Reply Parent Score: 4