<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Performance problem with an integer division benchmark"
href="http://llvm.org/bugs/show_bug.cgi?id=20205">20205</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Performance problem with an integer division benchmark
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows XP
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Keywords</th>
<td>code-quality
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>bearophile@mailas.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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 (<a href="http://forum.dlang.org/thread/chujnioihfjbqtjpshoz@forum.dlang.org">http://forum.dlang.org/thread/chujnioihfjbqtjpshoz@forum.dlang.org</a> )
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;
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>