Page 2 of 2
Matthew/Jack
Posted: Sat Jul 26, 2003 8:13 am
by LJ
Sure would be great if you guys could post an article in the Tricks n Tips section under the Purebasic Inline Assembly sticky. Something that would be appropriate for beginners with explanation would be great.
Lj
Posted: Sun Jul 27, 2003 3:44 am
by Flype
Is there a microsecond counter available to PB?
No, but the Windows API has one :
Posted: Sun Jul 27, 2003 9:27 am
by Pupil
Flype wrote:Is there a microsecond counter available to PB?
No, but the Windows API has one :
That's a millisecond counter and not a microsecond counter. Search the forum, i think there's a highres timer user library out there made by Danilo, if i'm not misstaken..
Posted: Fri Aug 20, 2004 7:35 pm
by thefool
ok this is an old post, but i would like to finnish it up.
Maybe it'll help other people too.
I made some things with the source, and i made the asm
faster than the pb version.
Debugger should be off.
Copy/paste source to your editor and run without debugger, then it should
show you. The tests may take a while on slow computers.
Well, the source:
Code: Select all
;Modulus test
;Code by: Daniel Middelhede -THEFOOL-
;NOTE: do not run with debugger on.
;And: run with inline asm enabled!
;And in case u dont turn off the debugger :P
Debug "Please turn of debugger!"
CallDebugger
;Just some info and opening of console..
OpenConsole()
PrintN("Modulus test")
PrintN("Copyright(c) 2004 Daniel Middelhede -THEFOOL-")
PrintN("Please close all other programs while running this!")
PrintN("")
PrintN("3 seconds to go..")
Delay(3000)
PrintN("Tests started!")
PrintN("")
;Change DIVIDEND and DIVISOR to change the division. But make sure the dividend and divisor is
;the same in the other part of code, the PB test!
dividend=100
divisor=42
time1=GetTickCount_()
MOV ebx, divisor ;Make diviser declared outside loop because it wont change!
For i=1 To 200000000 ;loop a lot.
;Ok. This is the ASM from the first post, wich i took and optimized a bit
;with making it direct.
MOV eax, dividend
!CDQ
!IDIV ebx
MOV dividend, edx
Next i
mytime= GetTickCount_()-time1
PrintN("PB Inline ASM modulus")
PrintN("Result: "+Str(dividend))
PrintN("Time : "+Str(mytime))
;**OK. Now we go to the PB test!
PrintN("")
divisor=42
dividend=100
time2=GetTickCount_()
divisor=42 ;Make diviser declared outside loop because it wont change!
For a=1 To 200000000 ;Loop alot.
;This is the PB code for modulus!
dividend=100
dividend - ((dividend / divisor) * divisor)
Next a
mytime2= GetTickCount_()-time2
PrintN("PB way modulus")
PrintN("Result: "+Str(dividend))
PrintN("Time : "+Str(mytime2))
PrintN("")
PrintN("Judgement:")
;**Ok this is the final judgement. This test will see if PB or ASM was faster.
If mytime<mytime2
PrintN("ASM won with: "+Str(mytime2-mytime)+" Milliseconds!")
Else
PrintN("PB won with: "+Str(mytime-mytime2)+" Milliseconds!")
EndIf
PrintN("")
PrintN("Press enter key to exit the test!")
Input()
Ill say it once more. Run WITHOUT debugger!
Cheers!
Posted: Fri Aug 20, 2004 10:05 pm
by fweil
@thefool,
Add this part to your code ...
Code: Select all
;**OK. Now we go to the FASM test!
PrintN("")
divisor=42
dividend=100
time3=GetTickCount_()
! MOV ecx, 1 ; For a=1 To Count ;Loop alot.
! MOV ebx, 42 ; divisor=42 ;Make diviser declared outside loop because it wont change!
! _For4:
! MOV eax, 100 ; dividend = 100
! CDQ
! IDIV ebx
! MOV dword [v_dividend], edx
! INC ecx ; Next a
! CMP ecx, dword [v_Count]
! JLE _For4
mytime3= GetTickCount_()-time3
PrintN("PB way modulus")
PrintN("Result: "+Str(dividend))
PrintN("Time : "+Str(mytime3))
optimization, remember, optimization !
Rgrds
Posted: Fri Aug 20, 2004 10:55 pm
by GreenGiant
@fweil I'm afraid your code brings up an error box for me.
PureBasic.asm [201]: CMP ecx, dword [v_Count]
error: undefined symbol.
I'm afraid I dont know enough about FASM to know whether its your code or an error with my system or anything.
Posted: Sat Aug 21, 2004 7:34 am
by fweil
GreenGiant,
You are right. You have to declare a Count.l = something so that this variable exist formerly. This is the number of times you want the loop to be executed.
Rgrds
Posted: Sat Aug 21, 2004 8:03 am
by thefool
thx to fweil.
The reason i posted this was because i coultn see it finnished. But its great to get even more speed.
something about your code: The loops are need to be in the same code.
An for..next loop. Because, that shouldnt change. I cant think of any
point except speed testing where the loop code should be faster.
And, the reason i didnt use mov eax,100 etc.. is that the end user should be able to change it. But anyway, thanks.