Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Which is faster: array or cursor?
Message
From
09/03/2009 17:41:25
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
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:
01386789
Views:
120
>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?

With exact same code, before any change, array version was faster 1 second. After adding m. prefix, array was faster several seconds.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform