Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which is faster: array or cursor?
Message
From
09/03/2009 16:10:54
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01386748
Message ID:
01386760
Views:
134
Cursor is fastest in my quick benchmark (by 3 seconds on 100,000 iterations), but I have to loop at least 10,000 times to see any significant difference between the 2 methods. For your 1,000 records, any way would take about the same time.
CLEAR

LOCAL ARRAY laTest [1000]

CREATE CURSOR Test (Test I)

FOR I = 1 TO 1000
	laTest[I] = I
	INSERT INTO Test VALUES (I)
ENDFOR

? "Array"
? DATETIME()

FOR J = 1 TO 100000
	FOR I = 1 TO 1000
		I = laTest[I]
	ENDFOR
ENDFOR

? DATETIME()

? "Cursor"
? DATETIME()

FOR J = 1 TO 100000
	SCAN
		I = Test.Test
	ENDSCAN
ENDFOR

? DATETIME()
>If I had 1000 values that I need to loop through (visit every node sequentially, not skip around) that needed very fast processing and they do not need disk storage... which would be faster... an array or a cursor?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform