Page 1 of 1

CallFunction VS. CallFunctionFast

Posted: Sun Dec 14, 2003 9:25 am
by Codemonger
I did some tests in regards to the speed difference of CallFuntion and CallFunction Fast. Their is a huge difference in speed, CallFunctionFast is more than 10 times faster. Very cool. Anyway I was just wandering the speed of calling a function through a com object with the Interface command ? Any ideas of how comparable the speed is ?

Posted: Sun Dec 14, 2003 10:54 am
by Danilo
See yourself:

Code: Select all

DisableDebugger ; !!!

Procedure XYZ()
  ProcedureReturn 12
EndProcedure

Procedure XYZ2(*this)
  ProcedureReturn 12
EndProcedure

Structure myObject
  vTable.l
  Function_XYZ.l
EndStructure

Interface myInterface
  XYZ()
EndInterface

object.myObject
object\vTable       = @object\Function_XYZ
object\Function_XYZ = @XYZ2()

obj.myInterface = object

#count = 99999999;9999999999
A$="The test begins and takes some time!"
B$="System is locked while the test runs... JUST WAIT!"
C$="The test *can* run several minutes!"
MessageRequester("ATTENTION!",A$+Chr(13)+B$+Chr(13)+C$,#MB_ICONEXCLAMATION)

Delay(500)
SetPriorityClass_(GetCurrentProcess_(),#REALTIME_PRIORITY_CLASS)

start = TimeGetTime_()
For a = 0 To #count
  XYZ()
Next a
Test1 = TimeGetTime_()-start

start = TimeGetTime_()
For a = 0 To #count
  obj\XYZ()
Next a
Test2 = TimeGetTime_()-start

SetPriorityClass_(GetCurrentProcess_(),#NORMAL_PRIORITY_CLASS)


A$ = "Result 1:"+StrU(Test1,#LONG)
B$ = "Result 2:"+StrU(Test2,#LONG)
MessageRequester("RESULT",A$+Chr(13)+B$,0)
Its the same function called directly and in an object.

Disable the debugger to get realistic results!

I´ve tested on the oldest and slowest system available here, a PIII-600.
The difference is 1,5 seconds for 100 million calls.

On a dual PIII-1000 the difference is 0,9 seconds for 100 million calls.

Posted: Sun Dec 14, 2003 11:39 am
by Fred
I think to get more realistic result, you have a put a parameter to XYZ() as well, as you fonction need a context (in COM it's the implicit object) else it wouldn't be the behaviour and the gap should decrease a bit (COM should be always slowest due to the inderect function call). Nice test tough.

Posted: Sun Dec 14, 2003 11:52 am
by Danilo
I want to compare as realistic and fair as i can, and this
means an object has always 1 parameter more than a procedure
that does the same.

If the procedure has 3 params, the same procedure in an object
has 4 params because ALWAYS '*this' is given to the object.

Here is the test again with 3 params for both procedures:

Code: Select all

DisableDebugger ; !!! 

Procedure XYZ(a,b,c) 
  ProcedureReturn 12 
EndProcedure 

Procedure XYZ2(*this,a,b,c) 
  ProcedureReturn 12 
EndProcedure 

Structure myObject 
  vTable.l 
  Function_XYZ.l 
EndStructure 

Interface myInterface 
  XYZ(a,b,c)
EndInterface 

object.myObject 
object\vTable       = @object\Function_XYZ 
object\Function_XYZ = @XYZ2() 

obj.myInterface = object 

#count = 99999999;9999999999 
A$="The test begins and takes some time!" 
B$="System is locked while the test runs... JUST WAIT!" 
C$="The test *can* run several minutes!" 
MessageRequester("ATTENTION!",A$+Chr(13)+B$+Chr(13)+C$,#MB_ICONEXCLAMATION) 

Delay(500) 
SetPriorityClass_(GetCurrentProcess_(),#REALTIME_PRIORITY_CLASS) 

start = TimeGetTime_() 
For a = 0 To #count 
  XYZ(1,2,3) 
Next a 
Test1 = TimeGetTime_()-start 

start = TimeGetTime_() 
For a = 0 To #count 
  obj\XYZ(1,2,3) 
Next a 
Test2 = TimeGetTime_()-start 

SetPriorityClass_(GetCurrentProcess_(),#NORMAL_PRIORITY_CLASS) 


A$ = "Result 1:"+StrU(Test1,#LONG) 
B$ = "Result 2:"+StrU(Test2,#LONG) 
MessageRequester("RESULT",A$+Chr(13)+B$,0)
What Fred said is also true, you can test this out for yourself.

Without objects, you call function(handle,x,y) for example.
OOP-Style you call the same as obj\function(x,y) and the handle
is saved in a variable in the object itself.