Wiki Home

Speed Tests


Namespace: WIN_COM_API
In trying to make an app as fast as posible, I ran some tests. The basic test code is below, the results are on top.
FasterSlowerNotesCode
"(" $ lcStrRight( lcStr, 1 ) = ")"for len( lcStr ) < 110
(regardless of if lcStr has a ( or not.)
You're searching for a ( in one and a ) in the other. If the ( is the first char wouldn't that mess up your timings? Shouldn't you be doing IF ")" $ lcStr instead? -- Mike Yearwood
If "(" $ lcStr
lcStr = StrExtract( lcStr, "", "(" )
lcStr = StrExtract( lcStr, "", "(", 0, 2 ) (regardless of if lcStr has a ( or not.)
lcStr = StrExtract( lcStr, "", "(" ) lcStr = LEFT(lcStr, AT("(", lcStr) - 1) About the same execution time
but I can read the StrExtract faster.
Evaluate(lcStr) &lcStr About time something made sense.
loObj = This.arrTest[2]
loObj.Value = "World"
This.arrTest[1].Value = "Hello" When setting an objects value, contained in an array, the access method of the array is called twice. __ Speed Test Array Assign


clear
loopsize = 500000

? "abc"
f("abc")
? "lots of x's"
f(Replicate( "X", 110 ))

Function f(tcStr)
? "  without ("
g( tcStr )
? "  with ("
g( tcStr+[(] )
Return

Function g(tcStr)
Local lcStr
lcStr = tcStr

? ["(" $ lcStr StrExtract(...)]
ltStart = Seconds()
For lnI = 1 to loopsize
	If "(" $ lcStr
		lcStr = StrExtract( lcStr, "", "(" )
	EndIf 
EndFor
ltEnd = Seconds()
? ltEnd - ltStart

? [StrExtract(...0, 2)]
ltStart = Seconds()
For lnI = 1 to loopsize
	lcStr = StrExtract( lcStr, "", "(", 0, 2 )
EndFor
ltEnd = Seconds()
? ltEnd - ltStart

Return

Similare issues: What is the better way to code equlivant SQL?
FasterSlowerNotes
WHERE key NOT IN (SELECT key...)LEFT JOIN on key=key WHERE key IS NULL
LEFT JOIN WHERE key IS NULLEFT JOIN key=key AND key IS NULLreturns an extra row?!


#Define loopsize 20

Clear
* clean up previous runs
On Error ? Message()
Drop Table TB
Drop Table TA
Close Databases all
Delete Database Foo deletetables 
On Error

Create Database foo
Create Table TA ( ;
	kTA_pk int primary key, ;
	cFid1 char(10) )
	
Create Table TB ( ;
	kTB_pk int primary key, ;
	kTA_fk int references TA,;
	cFid2 char(10) )

For lnI = 1 to loopsize
	Insert into TA (kTA_pk, cFid1) values ( lnI, "A" )
EndFor

? "Nothing in TB"
RunQueries()

? "loopsie in TB, no matches"
For lnJ = 1 to loopsize
	Insert into TB (kTB_pk, kTA_fk, cFid2) values ( lnJ, 0, "B" )
EndFor 
RunQueries()

? "loopsie in TB, 50% matches"

Update TB set kTA_fk = 1 where kTB_pk % 2 = 0
RunQueries()

? "loopsie in TB, all matches"
Update TB set kTA_fk = 1
RunQueries()

? "loopsize in A, 100x loopsize in B, 100% of A in B"
For lnJ =  loopsize+1 to loopsize * 100  && ( cuz of the data that is in there...)
	Insert into TB (kTB_pk, kTA_fk, cFid2) values ( lnJ, 0, "B" )
EndFor 
RunQueries()

? "loopsize in A, 100x loopsize in B, 50% of A in B"
Update TB set kTA_fk = 0 where kTB_pk % 2 = 0
RunQueries()

? "loopsize in A, 100x loopsize in B, 0% of A in B"
Update TB set kTA_fk = 0 
RunQueries()


Function RunQueries()

lTStart = StartTimer("key not in (select...")
Select * ;
	from TA ;
	where kTA_pk not in (select kTA_fk from TB) ;
	into cursor temp
StopTimer( lTStart )

lTStart = StartTimer("join where key is null")
Select * ;
	from TA left join TB on TA.kTA_pk = TB.kTA_fk ;
	where TB.kTA_fk is null ;
	into cursor temp
StopTimer( lTStart )

lTStart = StartTimer("join on key is null")
Select * ;
	from TA left join TB On TA.kTA_pk = TB.kTA_fk AND TB.kTA_fk is null ;
	into cursor temp
StopTimer( lTStart )

?
return

Function StartTimer( tcDesc )
? Padr( tcDesc, 50 )
Return Seconds()

Function StopTimer( tnStart )
lnEnd = Seconds()
lnElapsed = lnEnd - tnStart
?? Chr(9), lnElapsed, "secconds"
Return


Want to run this on SQL? No problem! Just run the Prg Up Sizer (no kidding.)
Contributors Carl Karsten
( Topic last updated: 2004.01.21 06:32:42 PM )