News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

PI

Started by Manos, March 17, 2019, 09:20:22 AM

Previous topic - Next topic

Manos

When we speak for performance of a compiler,
we usually mean the speed of the executable.
To compare several compilers, I upload an example
that computes the first 10000 digits of number pi.
Try the attachment with several C compilers.

If you try with my tools, use the following command lines:

pcc32 /c /MD pi.c
Link32 /SUBSYSTEM:CONSOLE pi.obj kernel32.lib complib.lib

Manos.

hutch--

Manos,

Post the executable with the source so we can test the exe.

Manos

Quote from: hutch-- on March 17, 2019, 05:09:13 PM
Manos,

Post the executable with the source so we can test the exe.

I send the source with three exacutables.

1). PI_MS.exe builded with MS C compiler.
2). pi_pcc32.exe builded with my Tools.
3). PI_PelleC.exe builded with PelleC compiler.

Manos.

Vortex

Hi Manos,

Thanks for the example. Here are my results :
PI_MS.exe
Begin of calculating Pi

Got  1000 digits of Pi
Got  2000 digits of Pi
Got  3000 digits of Pi
Got  4000 digits of Pi
Got  5000 digits of Pi
Got  6000 digits of Pi
Got  7000 digits of Pi
Got  8000 digits of Pi
Got  9000 digits of Pi
Got 10000 digits of Pi

End of calculating Pi

in 10453 ms
Printed Pi to Pi.txt


pi_pcc32.exe
Begin of calculating Pi

Got  1000 digits of Pi
Got  2000 digits of Pi
Got  3000 digits of Pi
Got  4000 digits of Pi
Got  5000 digits of Pi
Got  6000 digits of Pi
Got  7000 digits of Pi
Got  8000 digits of Pi
Got  9000 digits of Pi
Got 10000 digits of Pi

End of calculating Pi

in 10890 ms
Printed Pi to Pi.txt


PI_PelleC.exe
Begin of calculating Pi

Got  1000 digits of Pi
Got  2000 digits of Pi
Got  3000 digits of Pi
Got  4000 digits of Pi
Got  5000 digits of Pi
Got  6000 digits of Pi
Got  7000 digits of Pi
Got  8000 digits of Pi
Got  9000 digits of Pi
Got 10000 digits of Pi

End of calculating Pi

in 11359 ms
Printed Pi to Pi.txt

Manos

The results in my system, (Win7):

C:\>PI_MS.exe
Begin of calculating Pi

Got  1000 digits of Pi
Got  2000 digits of Pi
Got  3000 digits of Pi
Got  4000 digits of Pi
Got  5000 digits of Pi
Got  6000 digits of Pi
Got  7000 digits of Pi
Got  8000 digits of Pi
Got  9000 digits of Pi
Got 10000 digits of Pi

End of calculating Pi

in 3526 ms
Printed Pi to Pi.txt


C:\>pi_pcc32.exe
Begin of calculating Pi

Got  1000 digits of Pi
Got  2000 digits of Pi
Got  3000 digits of Pi
Got  4000 digits of Pi
Got  5000 digits of Pi
Got  6000 digits of Pi
Got  7000 digits of Pi
Got  8000 digits of Pi
Got  9000 digits of Pi
Got 10000 digits of Pi

End of calculating Pi

in 3712 ms
Printed Pi to Pi.txt


C:\>PI_PelleC.exe
Begin of calculating Pi

Got  1000 digits of Pi
Got  2000 digits of Pi
Got  3000 digits of Pi
Got  4000 digits of Pi
Got  5000 digits of Pi
Got  6000 digits of Pi
Got  7000 digits of Pi
Got  8000 digits of Pi
Got  9000 digits of Pi
Got 10000 digits of Pi

End of calculating Pi

in 4149 ms
Printed Pi to Pi.txt



Manos.

jj2007

Core i5
3764 pi_ms
3956 pi_pcc32
4689 pi_pellec

Manos

Below is the assembly source in MASM syntax with C comments
that pcc32 emits.

;File PI.c
;pcc32 version 1.0 release

title 'PI.c'
.486p
.model flat

.code
public _main
_main:
; Line 9: int main(int argc, char *argv[])

; Line 10: {

push 030D50h
call ___substackp
push ebx
push ebp
push esi
push edi
L_10:
; Line 13: clock_t ticks;

; Line 14:

; Line 15:     printf("Begin of calculating Pi\n\n");

push offset L_1
call _printf
pop ecx
; Line 16:

; Line 17:

; Line 18: ticks = clock();

call dword ptr [__imp__clock]
mov dword ptr [esp-08h+030D60h],eax
; Line 19:

xor eax,eax
L_13:
; Line 21:         r[l]=2;

mov dword ptr [esp+eax*4-02710Ch+030D60h],02h
L_16:
inc eax
; Line 20:     for (l=0; l<=e; l++)

L_14:
cmp eax,09C40h
jle L_13
L_15:
xor eax,eax
L_17:
; Line 23:         p[l]=0;

mov dword ptr [esp+eax*4-030D50h+030D60h],00h
L_20:
inc eax
; Line 22:     for (l=0; l<=f; l++)

L_18:
cmp eax,02710h
jle L_17
L_19:
; Line 24:    

; Line 25:    

; Line 26:    

mov eax,01h
mov dword ptr [esp-04h+030D60h],eax
L_21:
; Line 28:     {

; Line 29:         s=0;

xor ecx,ecx
mov ebx,09C40h
L_26:
; Line 31:         {

; Line 32:             a=i-1;

mov eax,ebx
dec eax
mov esi,eax
; Line 33:             b=a*2+1;

mov eax,esi
shl eax,01h
inc eax
mov ebp,eax
; Line 34:            

; Line 35:             z=r[i]*10+s;

mov eax,dword ptr [esp+ebx*4-02710Ch+030D60h]
imul eax,0Ah
mov edi,eax
add edi,ecx
; Line 36:             s=(z/b)*a;

mov ecx,ebp
mov eax,edi
mov edx,eax
sar edx,01Fh
cdq
idiv ecx
mov ecx,esi
imul ecx,eax
; Line 37:             r[i]=z%b;

mov esi,ebp
mov eax,edi
mov edx,eax
sar edx,01Fh
cdq
idiv esi
mov dword ptr [esp+ebx*4-02710Ch+030D60h],edx
L_29:
dec ebx
mov eax,ebx
; Line 30:         for (i=e; i>=2; i--)

L_27:
cmp ebx,02h
jge L_26
L_28:
; Line 38:         }

; Line 39:        

; Line 40:         z=r[i]*10+s;

mov eax,dword ptr [esp+ebx*4-02710Ch+030D60h]
imul eax,0Ah
mov ebx,eax
add ebx,ecx
; Line 41:         p[j]=z/10;

mov eax,ebx
mov edx,eax
sar edx,01Fh
mov ecx,0Ah
cdq
idiv ecx
mov ecx,dword ptr [esp-04h+030D60h]
mov dword ptr [esp+ecx*4-030D50h+030D60h],eax
; Line 42:         r[1]=z%10;

mov eax,ebx
mov edx,eax
sar edx,01Fh
mov ecx,0Ah
cdq
idiv ecx
mov dword ptr [esp-02710Ch+04h+030D60h],edx
; Line 43:        

; Line 44:        

; Line 45:         i=j;

mov eax,dword ptr [esp-04h+030D60h]
cmp dword ptr [esp+eax*4-030D50h+030D60h],09h
jle L_33
L_32:
; Line 47:         {

; Line 48:             p[i]=p[i]-10;

sub dword ptr [esp+eax*4-030D50h+030D60h],0Ah
; Line 49:             i--;

dec eax
; Line 50:             p[i]++;

inc dword ptr [esp+eax*4-030D50h+030D60h]
L_34:
; Line 46:         while (p[i]>9)

cmp dword ptr [esp+eax*4-030D50h+030D60h],09h
jg L_32
L_33:
; Line 51:         };

; Line 52:        

; Line 53:         if (j%1000==0)

mov eax,dword ptr [esp-04h+030D60h]
mov edx,eax
sar edx,01Fh
mov ecx,03E8h
cdq
idiv ecx
and edx,edx
jne L_37
; Line 54:             printf("Got %5d digits of Pi\n", j);

mov eax,dword ptr [esp-04h+030D60h]
push eax
push offset L_2
call _printf
pop ecx
pop ecx
L_37:
; Line 55:        

L_24:
inc dword ptr [esp-04h+030D60h]
; Line 27:     for (j=1; j<=f; j++)

L_22:
cmp dword ptr [esp-04h+030D60h],02710h
jle offset L_21
L_23:
; Line 56:     };

; Line 57:     printf("\nEnd of calculating Pi\n\n");

push offset L_3
call _printf
pop ecx
; Line 58:

; Line 59:     printf("in %lu ms\n", clock() - ticks);

mov eax,dword ptr [esp-08h+030D60h]
mov ebx,eax
call dword ptr [__imp__clock]
sub eax,ebx
push eax
push offset L_4
call _printf
pop ecx
pop ecx
; Line 60:

; Line 61:    

; Line 62:     #define LINE_LNG                100

; Line 63:     stream = fopen("Pi.txt","w");

push offset L_6
push offset L_5
call _fopen
pop ecx
pop ecx
mov ebx,eax
; Line 64:     setvbuf(stream, NULL, _IOFBF, 4096);

push 01000h
push 00h
push 00h
push ebx
call _setvbuf
add esp,010h
; Line 65:    

xor edi,edi
xor esi,esi
L_39:
; Line 67:     {

mov ebp,01h
L_44:
; Line 69:             fprintf(stream,"%d",p[j*LINE_LNG+i]);

mov eax,edi
add eax,ebp
mov eax,dword ptr [esp+eax*4-030D50h+030D60h]
push eax
push offset L_7
push ebx
call _fprintf
add esp,0Ch
L_47:
inc ebp
; Line 68:         for (i=1; i<=LINE_LNG; i++)

L_45:
cmp ebp,064h
jle L_44
L_46:
; Line 70:         fprintf(stream,"\n");

push offset L_8
push ebx
call _fprintf
pop ecx
pop ecx
L_42:
add edi,064h
inc esi
; Line 66:     for (j=0; j<=(f/LINE_LNG-1); j++)

L_40:
cmp edi,026ACh
jle L_39
L_41:
; Line 71:     };

; Line 72:     fclose(stream);

push ebx
call _fclose
pop ecx
; Line 73:     printf("Printed Pi to Pi.txt\n\n");

push offset L_9
call _printf
pop ecx
; Line 74:    

; Line 75:     return 0;

xor eax,eax
; Line 76: }

L_11:
pop edi
pop esi
pop ebp
pop ebx
add esp,030D50h
ret
_string segment use32 public dword "string"
L_9:
db "Printed Pi to Pi.txt"
db 0Ah
db 0Ah
db 00h
L_8:
db 0Ah
db 00h
L_7:
db "%d"
db 00h
L_6:
db "w"
db 00h
L_5:
db "Pi.txt"
db 00h
L_4:
db "in %lu ms"
db 0Ah
db 00h
L_3:
db 0Ah
db "End of calculating Pi"
db 0Ah
db 0Ah
db 00h
L_2:
db "Got %5d digits of Pi"
db 0Ah
db 00h
L_1:
db "Begin of calculating Pi"
db 0Ah
db 0Ah
db 00h
_string ends
_const segment use32 public dword "const"

_const ends
.code
extrn ___substackp:proc
extrn __imp__clock:proc
extrn _setvbuf:proc
extrn _printf:proc
extrn _fprintf:proc
extrn _fopen:proc
extrn _fclose:proc
end


Manos.

hutch--

Haswell E/EP

A:\PI\PI>pi_ms
Begin of calculating Pi

Got  1000 digits of Pi
Got  2000 digits of Pi
Got  3000 digits of Pi
Got  4000 digits of Pi
Got  5000 digits of Pi
Got  6000 digits of Pi
Got  7000 digits of Pi
Got  8000 digits of Pi
Got  9000 digits of Pi
Got 10000 digits of Pi

End of calculating Pi

in 3390 ms
Printed Pi to Pi.txt

A:\PI\PI>pi_pcc32
Begin of calculating Pi

Got  1000 digits of Pi
Got  2000 digits of Pi
Got  3000 digits of Pi
Got  4000 digits of Pi
Got  5000 digits of Pi
Got  6000 digits of Pi
Got  7000 digits of Pi
Got  8000 digits of Pi
Got  9000 digits of Pi
Got 10000 digits of Pi

End of calculating Pi

in 3656 ms
Printed Pi to Pi.txt

A:\PI\PI>pi_pelleC
Begin of calculating Pi

Got  1000 digits of Pi
Got  2000 digits of Pi
Got  3000 digits of Pi
Got  4000 digits of Pi
Got  5000 digits of Pi
Got  6000 digits of Pi
Got  7000 digits of Pi
Got  8000 digits of Pi
Got  9000 digits of Pi
Got 10000 digits of Pi

End of calculating Pi

in 3968 ms
Printed Pi to Pi.txt

Vortex

pcc32 :

End of calculating Pi

in 10453 ms
Printed Pi to Pi.txt

MinGW :

in 11531 ms
Printed Pi to Pi.txt

Manos

Calculating Pi by several compilers in my system:

pi_VStudio2008.exe

in 3510 ms
========================
pi_VStudio6.exe

in 3712 ms
========================
pi_pcc32.exe

in 3712 ms
========================
pi_pellec.exe

in 4149 ms
=========================
Pi-MinGW.exe

in 4726 ms
========================

Download the attachment.

Manos.