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
Inline ASM slower than equivalent PB code...
No, but the Windows API has one :Is there a microsecond counter available to PB?
Code: Select all
ticks = GetTickCount_()No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
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..Flype wrote:No, but the Windows API has one :Is there a microsecond counter available to PB?Code: Select all
ticks = GetTickCount_()
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:
Ill say it once more. Run WITHOUT debugger!
Cheers!
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()
Cheers!
@thefool,
Add this part to your code ...
optimization, remember, optimization !
Rgrds
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))
Rgrds
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
-
GreenGiant
- Enthusiast

- Posts: 252
- Joined: Fri Feb 20, 2004 5:43 pm
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
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
My avatar is a small copy of the 4x1.8m image I created and exposed at 'Le salon international du meuble à Paris' january 2004 in Matt Sindall's 'Shades' designers exhibition. The original laminated print was designed using a 150 dpi printout.
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.
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.

