prinft performance problem
bearophile
bearophileHUGS at lycos.com
Mon Mar 17 20:31:30 PDT 2014
I have reduced another performance problem, Windows 32 bit.
--------------------------
A test C program:
#include <stdio.h>
int main() {
for (double i = 0; i < 200000; i++)
printf("%f\n", i);
return 0;
}
--------------------------
A similar D program:
import core.stdc.stdio: printf;
int main() {
for (double i = 0; i < 200000; i++)
printf("%f\n", i);
return 0;
}
--------------------------
I compile with:
gcc -std=gnu99 -Ofast -flto -s test1.c -o test1
gcc 4.8.0
ldmd2 -wi -O -release -inline -noboundscheck test2.d
ldc2 0.13.0-alpha1
If I redirect the output to file, the run-times for me are about
0.30 seconds for the C version, and about 1.12 seconds for the D
version.
--------------------------
GCC asm:
_main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $32, %esp
call ___main
fldz
.p2align 4,,7
L4:
fstl 4(%esp)
movl $LC1, (%esp)
fstpl 24(%esp)
call _printf
fldl 24(%esp)
fadds LC2
flds LC3
fcomip %st(1), %st
ja L4
fstp %st(0)
xorl %eax, %eax
leave
ret
--------------------------
LDC2 asm:
__Dmain:
pushl %esi
subl $24, %esp
xorps %xmm0, %xmm0
movl $200000, %esi
.align 16, 0x90
LBB0_1:
movsd %xmm0, 16(%esp)
movsd %xmm0, 4(%esp)
movl $_.str, (%esp)
calll ___mingw_printf
movsd 16(%esp), %xmm0
addsd LCPI0_0, %xmm0
decl %esi
jne LBB0_1
xorl %eax, %eax
addl $24, %esp
popl %esi
ret
--------------------------
Bye,
bearophile
More information about the digitalmars-d-ldc
mailing list