Cost of calling a standard library function
From: The Half A Wannabee ("The)
Date: 02/28/04
- Next message: Beth: "Best integer to string routines"
- Previous message: donkey: "Re: Strings in asm"
- Next in thread: The Half A Wannabee: "Re: Cost of calling a standard library function"
- Reply: The Half A Wannabee: "Re: Cost of calling a standard library function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 28 Feb 2004 07:38:38 +0100
Code is given below. As you can see from the timings, calling the "Standard
library" routine is almost twice as slow as writing it yourself. And the
funny thing is, the straight, no mind, forward written RosAsm code, I wrote
*first*...performs best. This is the same code that Randall Hyde commented a
week back or so, that it was inefficient. Assume nothing. Even when Randall
speaks, be critical. Code is written in RosAsm.
http://betov.free.fr/RosAsm.html
Who would have guessed that Rep Movsd would be the slowest of them all ? It
is 20000 ticks SLOWER than the Windows API !! My plain "stupid" approach is
57282 ticks faster than this. 2X !
Yes, we push/pop esi and edi, but this is needed in real life ! "Nobody"
copies the same sourcerect to the same destinationrect 1_000_000 times,
unless for non productive test code like this. But as the results show, this
time the testcode is useful. At least on this machine. Test Machine is an
AMD 1800+ running at 1000 Mhz. (It was "cheap". Only I cant run it on
fullspeed, as it gets to warm..so how cheap is that )?
Start 1_000_000 calls to CopyRect :014 014
TimeStamp result___________________ :054287 054273
Start 1_000_000 calls to CopyRect_2 :054290 003
TimeStamp result___________________ :123789 069499
Start 1_000_000 calls to CopyRect_3 :123793 004
TimeStamp result___________________ :235348 111555
Start 1_000_000 calls to Win32 API :235352 004
TimeStamp result___________________ :319786 084434
CODE :
;Parameters are pointers to rectangles
Proc CopyRect:
Arguments @DestRect @SourceRect
mov eax D@SourceRect
mov edx D@DestRect
;left
mov ebx D$eax + TRect_Left | mov D$edx + TRect_Left ebx
;top
mov ebx D$eax + TRect_Top | mov D$edx + TRect_Top ebx
;right
mov ebx D$eax + TRect_Right | mov D$edx + TRect_Right ebx
;bottom
mov ebx D$eax + TRect_Bottom | mov D$edx + TRect_Bottom ebx
EndP
;Parameters are pointers to rectangles
Proc CopyRect2:
Arguments @DestRect @SourceRect
mov eax D@SourceRect
mov edx D@DestRect
PushRect D$eax
PopRect D$edx
EndP
;Parameters are pointers to rectangles
Proc CopyRect3:
Arguments @DestRect @SourceRect
push edi esi
mov esi D@SourceRect
mov edi D@DestRect
mov ecx 4
rep movsd
pop edi edi
EndP
;Above is the homebrew routines that gets tested, below is the test code.
Only the part we test are included. To get hold of the full sourcecode for
the (not yet completed) performance counter, take a look at theese two
links. Source code is included in the exefile, within the zip archive. Load
it into the RosAsm assmebler IDE using File/load to view the code. Hover the
mouse just below the menu to see the TITLE's navigator. Click on the one
thats says PerformanceCounter to see the full PerformanceCounter code.
http://www.szmyggenpv.com/downloads/FontSupport.Zip
http://www.szmyggenpv.com/downloads/Documentation.Zip
[TestCopyRect1:'Start 1_000_000 calls to CopyRect :' 0]
[TestCopyRect2:'Start 1_000_000 calls to CopyRect_2 :' 0]
[TestCopyRect3:'Start 1_000_000 calls to CopyRect_3 :' 0]
[TestCopyRect4:'Start 1_000_000 calls to Win32 API :' 0]
[TestRemark2: 'TimeStamp result___________________ :' 0]
TPerformanceCounter_SelfTest:
Push edi
mov D$WindowUtilDirectoryFlags 1
call WindowUtil_OleSupport_Start
call TPerformanceCounter_Create | mov D$PerformanceCounter edi
call TPerformanceCounter_Start
;Test 3 version of the CopyRect function
call TPerformanceCounter_TimeStampRemark TestCopyRect1
mov ecx 1_000_000
@TestPerformance:
push ecx
call CopyRect ARect BRect
pop ecx
dec ecx
jnz @TestPerformance
call TPerformanceCounter_TimeStampRemark TestRemark2
call TPerformanceCounter_TimeStampRemark TestCopyRect2
mov ecx 1_000_000
@TestPerformance1:
push ecx
call CopyRect2 ARect BRect
pop ecx
dec ecx
jnz @TestPerformance1
call TPerformanceCounter_TimeStampRemark TestRemark2
call TPerformanceCounter_TimeStampRemark TestCopyRect3
mov ecx 1_000_000
@TestPerformance2:
push ecx
call CopyRect2 ARect BRect
pop ecx
dec ecx
jnz @TestPerformance2
call TPerformanceCounter_TimeStampRemark TestRemark2
call TPerformanceCounter_TimeStampRemark TestCopyRect4
mov ecx 1_000_000
@TestPerformance3:
push ecx
call 'user32.CopyRect' ARect BRect
pop ecx
dec ecx
jnz @TestPerformance3
call TPerformanceCounter_TimeStampRemark TestRemark2
call TPerformanceCounter_Stop &FALSE
push edi esi
mov eax D$gDesktopDir
push eax
call FileManager_ComposeFullFileNameEAX D$eax + TString_Pchar
PerformanceFileName
push eax
Call TPerformanceCounter_SaveToTextFile D$eax + TString_Pchar
pop eax
call StringManager_DisposeString
pop eax
call StringManager_DisposeString
pop esi edi
Call TPerformanceCounter_Destroy
call WindowUtil_OleSupport_Shutdown
pop edi
;call TSkinSection_SetDisabled
call TSZSkinWindow_RepaintWindow
ret
____________________________________________________________________________
_____________
- Next message: Beth: "Best integer to string routines"
- Previous message: donkey: "Re: Strings in asm"
- Next in thread: The Half A Wannabee: "Re: Cost of calling a standard library function"
- Reply: The Half A Wannabee: "Re: Cost of calling a standard library function"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|