Very strange thing

Everything else that doesn't fall into one of the other PB categories.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Very strange thing

Post 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 :?:
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Suspect GetTickCount returns signed number.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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?!?!?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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
jack
Addict
Addict
Posts: 1358
Joined: Fri Apr 25, 2003 11:10 pm

Post by jack »

it could be code alignment, try inserting a number of ! NOP
in your asm procedure.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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

( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post 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
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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 :?: :?:
Fred
Administrator
Administrator
Posts: 18350
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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...
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post 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. :wink: :P
Post Reply