Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newer functions faster than older functions?
Message
From
29/10/2003 05:17:27
 
 
To
28/10/2003 13:27:51
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00843451
Message ID:
00843958
Views:
21
>Hi Fabio,

>If VFP compiler it implemented the on command SUBSTR(m.lcAll,m.lcStart)
>like a pointer shift on memory, the second solution exec with n^1 complexity,
>but it copy the SUBSTR(m.lcAll,m.lcStart) on a internal variable, and then exec the AT() search on it, result -> n^2 time.

Well, to be honest, I did not expect anything else. Substr() returns a string


The at() function is fast.

I suspect that for a one char searchfor string, an assembler routine is used.
Otherwise I think an algorithm is used (Boyer-Moore ??), as the search time decreases as the length of the searchfor string increases.
>>    1 0.351000000002387
>>    2 1.341000000000349
>>    3 0.980999999999767
>>    4 0.810999999994237
>>    5 0.690999999998894
>>    6 0.631000000001222
>>    7 0.561000000001513
>>    8 0.550999999999476
>>    9 0.500999999996566
>>   10 0.510999999998603
>>   11 0.460000000006403
>>   12 0.461000000002969
>>   13 0.411000000000058
>>   14 0.439999999995052
>>   15 0.400000000001455
>>   16 0.421000000002096
>>   17 0.389999999999418
>>   18 0.400999999998021
>>   19 0.370999999999185
>>   20 0.370000000002619
*---------------------------------------------------------------------------
function attest()
	
	local SearchIn, SearchFor, i, nTimes
	local TimeStart, TimeTaken, txt
	_cliptext = ''
	nTimes = 10
	
	for i = 1 to 20 step 1 
		SearchFor = left('abcdefghijklmnopqrstuvwxyz', i)
		SearchIn = repl('.', 8*1024*1024) + SearchFor 
		
		TimeStart = seconds()
		for j = 1 to nTimes
			=at(SearchFor, SearchIn )
		endfor
		TimeTaken = seconds() - TimeStart
		txt = '>>' + str(len(SearchFor),5) + ' ' + transform(TimeTaken)
		?txt
		_cliptext = _cliptext  + txt + chr(13)+chr(10)
		
	endfor
endfunc
*---------------------------------------------------------------------------
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform