Page 1 of 1
Very strange thing
Posted: Thu Nov 13, 2003 7:47 pm
by Psychophanta
Please, does anybody understand why in my PC (at least) there are always a speed difference executing apparently same code?
Code: Select all
Procedure.f distance(xx.f,yy.f)
!fld dword[esp] ;push xx to FPU stack (to st0)
!fmul st0,st0
!fld dword[esp+4] ;push yy value to FPU stack (to st0) (xx is now in st1)
!fmul st0,st0
!faddp
!fsqrt
EndProcedure
cx1=13:cx2=782:cy1=345:cy2=286
xx.f=cx2-cx1:yy.f=cy2-cy1
DisableDebugger
tt=gettickcount_()
!finit
For t=1 To 10000000
distance(xx,yy)
Next
EnableDebugger
Debug gettickcount_()-tt
Debug ""
;Debug result ;<---- **THIS**
Debug distance(cx2-cx1,cy2-cy1)
When disable marked line the speed results slower than if i active the marked line (marked with **THIS**) 8O

8O

Posted: Thu Nov 13, 2003 8:58 pm
by dmoc
Suspect GetTickCount returns signed number.
Posted: Thu Nov 13, 2003 9:18 pm
by blueznl
sounds like a bug to me, looks awfully similar to all my troubles with getting plgblt to work...
with the debugger of: everything worked all right
with the debugger on things would depend on the amount of code?!?!?
Posted: Thu Nov 13, 2003 11:03 pm
by Fred
The debugger actually runs in a thread, that's why it can eat more or less CPU time. For speed test, you have to disable completely the debugger.
Posted: Fri Nov 14, 2003 11:02 am
by Psychophanta
Code: Select all
Procedure.f distance(xx.f,yy.f)
!fld dword[esp] ;push xx to FPU stack (to st0)
!fmul st0,st0
!fld dword[esp+4] ;push yy value to FPU stack (to st0) (xx is now in st1)
!fmul st0,st0
!faddp
!fsqrt
EndProcedure
cx1=13:cx2=782:cy1=345:cy2=286
xx.f=cx2-cx1:yy.f=cy2-cy1
;DisableDebugger
tt=gettickcount_()
!finit
For t=1 To 10000000
distance(xx,yy)
Next
;EnableDebugger
MessageRequester("",Str(gettickcount_()-tt),0)
;Debug gettickcount_()-tt
;Debug ""
;Debug result ;<---- **THIS**
;Debug distance(cx2-cx1,cy2-cy1)
With above code and debugger completely disabled i get 700 msecs.
Code: Select all
Procedure.f distance(xx.f,yy.f)
!fld dword[esp] ;push xx to FPU stack (to st0)
!fmul st0,st0
!fld dword[esp+4] ;push yy value to FPU stack (to st0) (xx is now in st1)
!fmul st0,st0
!faddp
!fsqrt
EndProcedure
cx1=13:cx2=782:cy1=345:cy2=286
xx.f=cx2-cx1:yy.f=cy2-cy1
DisableDebugger
tt=gettickcount_()
!finit
For t=1 To 10000000
distance(xx,yy)
Next
EnableDebugger
;MessageRequester("",Str(gettickcount_()-tt),0)
Debug gettickcount_()-tt
Debug ""
Debug result ;<---- **THIS**
Debug distance(cx2-cx1,cy2-cy1)
But with this last one and debugger enabled i get 570 msecs. 8O
Posted: Fri Nov 14, 2003 12:14 pm
by jack
it could be code alignment, try inserting a number of ! NOP
in your asm procedure.
Posted: Fri Nov 14, 2003 1:23 pm
by blueznl
try this, now the debugger should not affect the loop, and compare it with a completely disabled debugger
Code: Select all
Procedure.f distance(xx.f,yy.f)
!fld dword[esp] ;push xx to FPU stack (to st0)
!fmul st0,st0
!fld dword[esp+4] ;push yy value to FPU stack (to st0) (xx is now in st1)
!fmul st0,st0
!faddp
!fsqrt
EndProcedure
cx1=13:cx2=782:cy1=345:cy2=286
xx.f=cx2-cx1:yy.f=cy2-cy1
;DisableDebugger
tt=gettickcount_()
!finit
For t=1 To 10000000
distance(xx,yy)
Next
ttt=gettickcount_()
;EnableDebugger
MessageRequester("",ttt-tt),0)
;Debug gettickcount_()-tt
;Debug ""
;Debug result ;<---- **THIS**
;Debug distance(cx2-cx1,cy2-cy
Posted: Fri Nov 14, 2003 1:29 pm
by Pupil
> But with this last one and debugger enabled i get 570 msecs.
i get the opposite result, the first example(without debugger) aprox 570 ms and the example with debugger aprox. 700 ms
Posted: Fri Nov 14, 2003 3:41 pm
by Psychophanta
>i get the opposite result, the first example(without debugger) aprox 570 ms and the example with debugger aprox. 700 ms
How is possible? I promise you i am not wrong, i've tested it.
(Compilation options: Windows-All CPU, no NT4.0 compatible, no ASM, no XP themes, no enable OnError lines support)
blueznl, your example give me the same, 700 msec., with debugger disabled, of course.
jack wrote:
>it could be code alignment, try inserting a number of ! NOP in your asm procedure
code alignment? if i put a !nop at the beginning of procedure thigs change a little bit, i get 20 ms. more of difference in the debugger enabled example

Posted: Fri Nov 14, 2003 4:10 pm
by Fred
With new CPU, asm isn't as easy than before and sometimes behave strangely. It's widely due to processor cache and instruction alignment/order... I get shock to see than on my CPU, reading a variable is faster than reading a constant...
Posted: Fri Nov 14, 2003 4:29 pm
by Psychophanta
Aha, i see. Caches and newest performances ...
We are beginning to expect not so logical happenings with newests CPUs.
We are beginning a new era of indomitables CPUs.
