Page 1 sur 3

WrapAngle rapide

Publié : ven. 13/janv./2006 19:32
par comtois
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 ?

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) 
Voici mes résultats
---------------------------
Test
---------------------------
WrapAngle1 = 891

WrapAngle2 = 890

WrapAngle3 = 875

WrapAngleDeg = 860

WrapValue = 500
---------------------------
OK
---------------------------
et les siens

Image

Publié : ven. 13/janv./2006 19:35
par Chris
WrapAngle1 = 344
WrapAngle2 = 359
WrapAngle3 = 328
WrapAngleDeg = 297
WrapValue = 609
AMD Athlon 2000+ 1.67 GHz

Publié : ven. 13/janv./2006 19:37
par KarLKoX
WrapAngle1 = 265
WrapAngle2 = 297
WrapAngle3 = 266
WrapAngleDeg = 250
WrapValue = 500

CPU = AMD64 3500+ core Venice

Publié : ven. 13/janv./2006 19:44
par cederavic
WrapAngle1 = 234
WrapAngle2 = 297
WrapAngle3 = 250
WrapAngleDeg = 235
WrapValue = 468

Amd athlon xp 3100+

Publié : ven. 13/janv./2006 19:45
par comtois
je vois , il faut un AMD pour que ce soit plus rapide ?
quelqu'un a un pentium ? ou je suis le seul du forum ? :)

Publié : ven. 13/janv./2006 19:46
par Patrick88
WrapAngle1 = 438
WrapAngle2 = 453
WrapAngle3 = 422
WrapAngleDeg = 375
WrapValue = 812

Amd sempron 2600

c'est marrant plus je le fait tourner plus les nombres diminuent ...

pat

Publié : ven. 13/janv./2006 19:47
par Chris
Dobro, il me semble.

Publié : ven. 13/janv./2006 19:51
par Gillou
J'ai un P4 3, 4 GHz

WrapAngle1 = 766
WarpAngle2 = 796
WarpAngle3 = 750
WarpAngleDeg = 782
WarpValue = 468

Publié : ven. 13/janv./2006 19:52
par comtois
merci à tous , ça se confirme :)

Publié : ven. 13/janv./2006 20:00
par cederavic
Gillou a écrit :J'ai un P4 3, 4 GHz

WrapAngle1 = 766
WarpAngle2 = 796
WarpAngle3 = 750
WarpAngleDeg = 782
WarpValue = 468
3.2 GHz?!?!

Seulement 2.2GHz mon Athlon xp 3100+ et la difference est enorme!

Publié : ven. 13/janv./2006 20:07
par flaith
AMD Athlon 1,4Ghz :wink:
---------------------------
Test
---------------------------
WrapAngle1 = 401

WrapAngle2 = 551

WrapAngle3 = 420

WrapAngleDeg = 401

WrapValue = 761
---------------------------
OK
---------------------------

Publié : ven. 13/janv./2006 20:12
par CameleonTH
En faite si le processeur est un Intel c'est plus rapide avec WrapValue1 ,mais si c'est un AMD c'est plus rapide avec WrapvalueDeg.

Publié : ven. 13/janv./2006 20:24
par Heis Spiter
Voila avec mon petit Celeron 1.2Ghz :
WrapAngle1 = 704
WrapAngle2 = 734
WrapAngle3 = 719
WrapAngleDeg = 640
WrapValue = 1297

Publié : ven. 13/janv./2006 21:43
par Frenchy Pilou
Wrap Angle Value = 226
Wrap Angle Value = 265
Wrap Angle Value = 266
Wrap Angle DegValue = 234
Wrap Angle Value = 485

Amd Athlon 2600+ (1.91) Ghz

Mais je n'ai aucune idée de ce que fait cette fonction :roll:
C'est pour de l'astronomie ?

Publié : ven. 13/janv./2006 21:54
par comtois
elle permet de maintenir un angle entre 0 et 360° exclu .
720° sera converti en 0°.-45° en 315°.


Psychophanta a aussi écrit une fonction qui maintient un angle entre -180 à 180 degrés.

J'utilise bcp cette fonction dans les applis 3D .