[Issue 4447] New: order of functions greatly affects execution time
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jul 11 09:03:21 PDT 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4447
Summary: order of functions greatly affects execution time
Product: D
Version: D1 & D2
Platform: Other
OS/Version: Linux
Status: NEW
Severity: normal
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: braddr at puremagic.com
--- Comment #0 from Brad Roberts <braddr at puremagic.com> 2010-07-11 09:03:17 PDT ---
(split from bug 859)
=========== code ============
extern(C) int printf(const char*, ...);
extern(C) uint sleep(uint);
struct vector3 {
float x;
float y;
float z;
}
class Timer {
static long getTime() {
asm {
naked;
rdtsc;
ret;
}
}
long starttime;
string label;
this() {
starttime = getTime();
}
this(string label) {
starttime = getTime();
this.label = label;
}
~this() {
long endTime = getTime();
if (label !is null) {
printf("%*s ", label);
}
printf("time: %ld\n", endTime - starttime);
}
}
float DOT(ref vector3 A, ref vector3 B) {
return A.x * B.x + A.y * B.y + A.z * B.z;
}
void fooCompiler(ref vector3 a, ref vector3 b)
{
scope Timer t = new Timer();
float d = DOT(a, b);
printf("compiler: d = %f, %p ", d, &d);
}
void fooManual(ref vector3 a, ref vector3 b)
{
scope Timer t = new Timer();
float d = a.x * b.x + a.y * b.y + a.z * b.z;
printf("manual: d = %f, %p ", d, &d);
}
void main() {
vector3 a = { 1, 2, 3 };
vector3 b = { 4, 5, 6 };
version(warm)
{{
scope t = new Timer();
float d = 1.0;
printf("float rewarm: %f\n", d);
}}
version(one)
{
fooManual(a, b);
fooCompiler(a, b);
}
version(two)
{
fooCompiler(a, b);
fooManual(a, b);
}
}
=====================
$ dmd -inline -O -release -version=one odd.d
$ ./odd
manual: d = 32.000000, 0xbf96e2e0 time: 218169
compiler: d = 32.000000, 0xbf96e2e0 time: 11543
$ dmd -inline -O -release -version=two odd.d
$ ./odd
compiler: d = 32.000000, 0xbf8e98e0 time: 217847
manual: d = 32.000000, 0xbf8e98e0 time: 11452
$ dmd -inline -O -release -version=one -version=warm odd.d
$ ./odd
float rewarm: 1.000000
time: 227647
manual: d = 32.000000, 0xbf9e86b0 time: 27762
compiler: d = 32.000000, 0xbf9e86b0 time: 8316
$ dmd -inline -O -release -version=two -version=warm odd.d
$ ./odd
float rewarm: 1.000000
time: 229782
compiler: d = 32.000000, 0xbf9ed650 time: 27664
manual: d = 32.000000, 0xbf9ed650 time: 7987
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list