Bravo Denis, du remporte le premier prix de la catégorie procédure
Code : Tout sélectionner
Global Time1,Time2
Global a.b,b.l
Procedure SignedBinaryToUnsigned(byte.b)
If byte & %10000000
byte=byte & %01111111
Retour=byte+128
Else
Retour=byte
EndIf
ProcedureReturn Retour
EndProcedure
Procedure SignedBinaryToUnsignedASM(byte.b)
!MOV dword [esp+1],eax
ProcedureReturn Retour
EndProcedure
Procedure SignedBinaryToUnsignedDenis(byte.b)
ProcedureReturn byte & $FF
EndProcedure
Procedure SignedBinaryToUnsignedFred(byte.b)
Retour=byte & $FF
ProcedureReturn Retour
EndProcedure
If OpenWindow(1,200,200,350,200,#PB_Window_SystemMenu,"Programme de test")
Time1.l = GetTickCount_()
For t=1 To 10000000
;/ Unsigned Signed
b = SignedBinaryToUnsigned(%00000000) ; 0 0
b = SignedBinaryToUnsigned(%01111111) ; 127 127
b = SignedBinaryToUnsigned(%10000000) ; 128 -128
b = SignedBinaryToUnsigned(%11111111) ; 255 -1
Next
Time2.l = GetTickCount_()
StartDrawing(WindowOutput())
FrontColor(0,0,0)
DrawingMode(1)
Locate(20,10):DrawText("Durée Procedure Droopy (en ms) :")
Locate(280,10):DrawText(Str(Time2-Time1))
StopDrawing()
Time1.l = GetTickCount_()
For t=1 To 10000000
;/ Unsigned Signed
b = SignedBinaryToUnsignedASM(%00000000) ; 0 0
b = SignedBinaryToUnsignedASM(%01111111) ; 127 127
b = SignedBinaryToUnsignedASM(%10000000) ; 128 -128
b = SignedBinaryToUnsignedASM(%11111111) ; 255 -1
Next
Time2.l = GetTickCount_()
StartDrawing(WindowOutput())
FrontColor(0,0,0)
DrawingMode(1)
Locate(20,40):DrawText("Durée Procedure ASM (en ms) :")
Locate(280,40):DrawText(Str(Time2-Time1))
StopDrawing()
Time1.l = GetTickCount_()
For t=1 To 10000000
;/ Unsigned Signed
b = SignedBinaryToUnsignedDenis(%00000000) ; 0 0
b = SignedBinaryToUnsignedDenis(%01111111) ; 127 127
b = SignedBinaryToUnsignedDenis(%10000000) ; 128 -128
b = SignedBinaryToUnsignedDenis(%11111111) ; 255 -1
Next
Time2.l = GetTickCount_()
StartDrawing(WindowOutput())
FrontColor(0,0,0)
DrawingMode(1)
Locate(20,70):DrawText("Durée Procedure Denis (en ms) :")
Locate(280,70):DrawText(Str(Time2-Time1))
StopDrawing()
Time1.l = GetTickCount_()
For t=1 To 10000000
;/ Unsigned Signed
b = SignedBinaryToUnsignedFred(%00000000) ; 0 0
b = SignedBinaryToUnsignedFred(%01111111) ; 127 127
b = SignedBinaryToUnsignedFred(%10000000) ; 128 -128
b = SignedBinaryToUnsignedFred(%11111111) ; 255 -1
Next
Time2.l = GetTickCount_()
StartDrawing(WindowOutput())
FrontColor(0,0,0)
DrawingMode(1)
Locate(20,100):DrawText("Durée Procedure Fred (en ms) :")
Locate(280,100):DrawText(Str(Time2-Time1))
StopDrawing()
Time1.l = GetTickCount_()
For t=1 To 10000000
;/ Unsigned Signed
a = %00000000
b = a & $FF ; 0 0
a = %01111111
b = a & $FF ; 127 127
a = %10000000
b = a & $FF ; 128 -128
a = %11111111
b = a & $FF ; 255 -1
Next
Time2.l = GetTickCount_()
StartDrawing(WindowOutput())
FrontColor(0,0,0)
DrawingMode(1)
Locate(20,130):DrawText("Durée direct en PureBasic (en ms) :")
Locate(280,130):DrawText(Str(Time2-Time1))
StopDrawing()
Time1.l = GetTickCount_()
For t=1 To 10000000
;/ Unsigned Signed
a = %00000000
!MOV bl,byte [v_a]
!AND ebx,255
!MOV dword [v_b],ebx ; 0 0
a = %01111111
!MOV bl,byte [v_a]
!AND ebx,255
!MOV dword [v_b],ebx ; 127 127
a = %10000000
!MOV bl,byte [v_a]
!AND ebx,255
!MOV dword [v_b],ebx ; 128 -128
a = %11111111
!MOV bl,byte [v_a]
!AND ebx,255
!MOV dword [v_b],ebx ; 255 -1
Next
Time2.l = GetTickCount_()
StartDrawing(WindowOutput())
FrontColor(0,0,0)
DrawingMode(1)
Locate(20,160):DrawText("Durée direct en ASM (en ms) :")
Locate(280,160):DrawText(Str(Time2-Time1))
StopDrawing()
Repeat
EventID = WaitWindowEvent()
Until EventID = #PB_EventCloseWindow
EndIf