WrapAngle rapide
Publié : ven. 13/janv./2006 19:32
PsychoPhanta a écrit quelques procédures en assembleur et j'ai comparé avec la fonction écrite par filperj ,et chez moi c'est la fonction wrapvalue de filperj la plus rapide ,et c'est le contraire pour psychoPhanta . Et pour vous ?
Voici mes résultats

Code : Tout sélectionner
;PureBasic 3.94
;Pour une version 4.0 voir le lien ci-dessous
; http://purebasic.fr/english/viewtopic.php?t=18635
DisableDebugger
Procedure.f WrapAngle1(angle.f); <- wraps a value into [0,2*Pi) fringe
!fldpi
!fadd st0,st0; <- now i have 2*pi into st0
!fld dword[esp]
!fprem1
!ftst ;test to see if modulo <= 0
!fstsw ax ;transfers FPU status word to ax
!sahf ;transfers ah to CPU flags.
!jnc near @f ;if number has a negative value (modulo <= 0) then:
!fadd st0,st1
!@@:fstp st1
EndProcedure
Procedure.f WrapAngle2(angle.f); <- wraps a value into [0,2*Pi) fringe
!fldpi
!fadd st0,st0; <- now i have 2*pi into st0
!fld dword[esp]
!fprem1
!fadd st1,st0
!fldz
!fcomip st1
!fcmovnbe st0,st1
!fstp st1
EndProcedure
Procedure.f WrapAngle3(f1.f); <- wraps a value into [0,2*Pi) fringe
!fldpi
!fadd st0,st0; <- now i have 2*pi into st0
!fld dword[esp]
!fprem1
!ftst ;test to see if modulo <= 0
!fnstsw ax ;transfers FPU status word to ax
!fwait
!sahf ;transfers ah to CPU flags.
!jnc near @f ;if number has a negative value (modulo <= 0) then:
!fadd st0,st1
!@@:fstp st1
EndProcedure
Procedure.f WrapAngleDeg(angle.f); <- wraps a value into [0,360) fringe
!fild dword[@f] ; <- now i have 360 into st0
!fld dword[esp]
!fprem1
!fadd st1,st0
!fldz
!fcomip st1
!fcmovnbe st0,st1
!fstp st1
ProcedureReturn
!@@:dd 360
EndProcedure
Procedure.f WrapValue(Angle.f)
;Auteur Filperj
Angle/360
Angle-Int(Angle)
If Angle<0
ProcedureReturn (Angle+1)*360
Else
ProcedureReturn Angle*360
EndIf
EndProcedure
;It works in radians.
;Usage examples for degrees:
#PI=3.14159265:#DEGTORAD=0.01745329:#RADTODEG=57.2957795
#Max= 1000000
;1er Test
i.f=0
Tps=ElapsedMilliseconds()
While i < #Max
angleNew.f=WrapAngle1(i*#DEGTORAD)*#RADTODEG
i + 0.1
Wend
Total1=ElapsedMilliseconds()-Tps
;2eme Test
i.f=0
Tps=ElapsedMilliseconds()
While i < #Max
angleNew.f=WrapAngle2(i*#DEGTORAD)*#RADTODEG
i + 0.1
Wend
Total2=ElapsedMilliseconds()-Tps
;3eme Test
i.f=0
Tps=ElapsedMilliseconds()
While i < #Max
angleNew.f=WrapAngle3(i*#DEGTORAD)*#RADTODEG
i + 0.1
Wend
Total3=ElapsedMilliseconds()-Tps
;4eme Test
i.f=0
Tps=ElapsedMilliseconds()
While i < #Max
angleNew.f=WrapAngleDeg(i)
i + 0.1
Wend
Total4=ElapsedMilliseconds()-Tps
;5eme test
i.f=0
Tps=ElapsedMilliseconds()
While i < #Max
angleNew.f=WrapValue(i)
i + 0.1
Wend
Total5=ElapsedMilliseconds()-Tps
MessageRequester("Test","WrapAngle1 = " + Str(Total1) + #LFCR$ + "WrapAngle2 = " + Str(Total2) + #LFCR$ + "WrapAngle3 = " + Str(Total3) + #LFCR$ + "WrapAngleDeg = " + Str(Total4) + #LFCR$ + "WrapValue = " + Str(Total5),0)
et les siens---------------------------
Test
---------------------------
WrapAngle1 = 891
WrapAngle2 = 890
WrapAngle3 = 875
WrapAngleDeg = 860
WrapValue = 500
---------------------------
OK
---------------------------
