Code : Tout sélectionner
Procedure PGCD(number1.l, number2.l)
If number2 > number1
number3 = number1
number1 = number2
number2 = number3
EndIf
result = 2
i=0
While result <> 0
reste = number1 % number2
quotient = number1/number2
If reste = 0
If i = 0
ProcedureReturn number2
Else
ProcedureReturn reste2
EndIf
result=0
EndIf
number1 = number2
number2 = reste
reste2 = reste
i = i + 1
Wend
EndProcedure
Procedure c_PGCD(number1.l, number2.l)
Static l_number1, l_number2, l_result
! mov ecx, dword [esp]
! mov edx, dword [esp+4]
! cmp ecx, edx
! jae _nx
! xchg ecx, edx
! _nx :
! mov dword [esp], ecx
! mov dword [esp+4], edx
! mov ebx, dword [s_c_pgcd.v_l_number1]
! cmp ebx, dword [esp]
! jne _pgcd
! mov ebx, dword [s_c_pgcd.v_l_number2]
! cmp ebx, dword [esp+4]
! jne _pgcd
! mov eax, dword [s_c_pgcd.v_l_result]
ProcedureReturn
! _pgcd :
! mov dword [s_c_pgcd.v_l_number1], ecx
! mov dword [s_c_pgcd.v_l_number2], edx
result = 2
i=0
While result <> 0
reste = number1 % number2
quotient = number1/number2
If reste = 0
If i = 0
l_result = number2
ProcedureReturn number2
Else
l_result = reste2
ProcedureReturn reste2
EndIf
result=0
EndIf
number1 = number2
number2 = reste
reste2 = reste
i = i + 1
Wend
EndProcedure
Start1 = ElapsedMilliseconds()
For i = 0 To 5000000
PGCD(5000, 2500)
Next i
End1 = ElapsedMilliseconds()-Start1
Start2 = ElapsedMilliseconds()
For i = 0 To 5000000
c_PGCD(5000, 2500)
Next i
End2 = ElapsedMilliseconds()-Start2
;----
Start3 = ElapsedMilliseconds()
For i = 0 To 5000000
PGCD(2500, 5000)
Next i
End3 = ElapsedMilliseconds()-Start3
Start4 = ElapsedMilliseconds()
For i = 0 To 5000000
c_PGCD(2500, 5000)
Next i
End4 = ElapsedMilliseconds()-Start4
Msg.s = "PGCD(5000, 2500) in "+Str(End1)+"ms"+Chr(13)+Chr(10)
Msg.s = Msg+"c_PGCD(5000, 2500) in "+Str(End2)+"ms"+Chr(13)+Chr(10)
Msg.s = Msg+"PGCD(2500, 5000) in "+Str(End3)+"ms"+Chr(13)+Chr(10)
Msg.s = Msg+"c_PGCD(2500, 5000) in "+Str(End4)+"ms"+Chr(13)+Chr(10)
MessageRequester("Test", Msg)