Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
COPY TO ARRAY against a cursor?
Message
From
08/08/2019 07:46:52
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
07/08/2019 15:57:31
John Ryan
Captain-Cooker Appreciation Society
Taumata Whakatangi ..., New Zealand
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01669872
Message ID:
01669991
Views:
78
OK I see we don't understand each other and the same test has very different results on either side which makes me think it is not reliable at all. Probably you wouldn't use this always against the sample "Employee" table. I could play with the test a bit and get much different striking results that would tell COPY TO ARRAY is slower more than 100x. ie:
Clear All
Clear
Set Talk Off
#Define mainrows 100000
#Define childmax 20
#Define iterations 100
Local ix, jx, lcResult, Start, elapsed

Create Cursor myTest (Id i Autoinc, parentId i, Value c(10))
For ix=1 To mainrows
	For jx=1 To Rand(-1)*childmax+1
		Insert Into myTest (parentId, Value) Values (m.ix, Sys(2015))
	Endfor
Endfor
Index On Id Tag Id
Index On parentId Tag parentId

Set Textmerge To Memvar m.lcResult On Noshow
Start = Seconds()
For ix = 1 To iterations
	Copy To Array laTest For parentId = 50
Endfor
elapsed = Seconds()-m.start
\COPY TO ARRAY - Rows: << Alen(laTest,1) >>, Elapsed: << m.elapsed >>

Start = Seconds()
For ix = 1 To iterations
	Select * From myTest Where parentId = 50 ;
		into Array laTest
Endfor
elapsed = Seconds()-m.start
\SELECT INTO ARRAY - Rows: << Alen(laTest,1) >>, Elapsed: << m.elapsed >>

Start = Seconds()
For ix = 1 To iterations
	Select * From myTest Where parentId = 50 ;
		into Cursor crsTest nofilter
Endfor
elapsed = Seconds()-m.start
\SELECT INTO CURSOR - Rows: << Reccount('crsTest') >>, Elapsed: << m.elapsed >>

Set Textmerge To
Set Textmerge Off

_Cliptext = m.lcResult
? m.lcResult

*!*	COPY TO ARRAY - Rows: 17, Elapsed: 1.920
*!*	SELECT INTO ARRAY - Rows: 17, Elapsed: 0.015
*!*	SELECT INTO CURSOR - Rows: 17, Elapsed: 0.016
And interestingly, provided we have at least one row, only COPY TO ARRAY needs a "RELEASE" in the code (anyway didn't include it to make it even more slower).

>>>PS: For cursor test, you should include NOFILTER for a true cursor ...
>
>Generally agree, though a filtered cursor in context isn't a bad comparison.
>
>>>and remove "release aFrance..." which explicitly makes it lose more time for no reason. And you should include Local array declaration. That is what one normally want to do in real world app.
>
>I commented out LOCAL aFranceEmps[1] because COPY TO ARRAY does not increase the size of the Array if it already exists. So in this case, COPY TO ARRAY would populate only one array element first time. Put a breakpoint after COPY TO ARRAY to confirm. If you put LOCAL aFranceEmps[1] back and comment out the RELEASE aFranceEmps , now Copy to Array populates only one element every time. So not a fair test:
>
>Using COPY TO ARRAY, 10000 passes took 0.024; records in result = 1
>Using SQL SELECT, 10000 passes took 0.518; records in result = 12
>Using SQL SELECT to cursor, 10000 passes took 0.517; records in result = 12
>
>Another reason I had for Release aFranceEmps is that in real use, COPY TO ARRAY can't rely on an existing array of the exact correct dimensions and size to reuse every time, which is what this test would give it.
>
>Experimenting with and without RELEASE, I saw very little difference- COPY TO ARRAY a few hundredths of a second quicker without RELEASE, SELECT about the same.
Ç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