[LLVMbugs] [Bug 20205] New: Performance problem with an integer division benchmark

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jul 4 09:48:26 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20205

            Bug ID: 20205
           Summary: Performance problem with an integer division benchmark
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Windows XP
            Status: NEW
          Keywords: code-quality
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bearophile at mailas.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

While running a little benchmark on the LDC compiler (version 0.13.0 based on
DMD v2.064 and LLVM 3.4.2), I have found it being significantly (like five
times) slower than equivalent C code compiled with GCC 4.8.0 (using -O3
-std=c99, do not use -O2) on a 32 bit Windows system. Later others in the D
newsgroup (http://forum.dlang.org/thread/chujnioihfjbqtjpshoz@forum.dlang.org )
have confirmed it's not a LDC problem, but a back-end problem.

The title of this issue is generic because I don't know the exact causes. Feel
free to rename it.

The C code:


#include <stdio.h>
#include <stdbool.h>

const int t = 20;

bool isEvenlyDivisible(const int i, const int a, const int b) {
    if (i > b)
        return true;
    else
        return (a % i == 0) && isEvenlyDivisible(i + 1, a, b);
}

void run() {
    int i = 10;
    while (!isEvenlyDivisible(2, i, t))
        i += 2;
    printf("%d\n", i);
}

int main() {
    for (int i = 0; i < 5; i++)
      run();
    return 0;
}

------------------

The C-style D version:

import core.stdc.stdio;

enum int t = 20;

bool isEvenlyDivisible(in int i, in int a, in int b)
pure nothrow @safe {
    if (i > b)
        return true;
    else
        return (a % i == 0) && isEvenlyDivisible(i + 1, a, b);
}

void run() nothrow {
    int i = 10;
    while (!isEvenlyDivisible(2, i, t))
        i += 2;
    printf("%d\n", i);
}

void main() {
    for (int i = 0; i < 5; i++)
      run;
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140704/63d792cf/attachment.html>


More information about the llvm-bugs mailing list