Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Issue: Collection.Clear(), I don't find it.
Message
From
14/05/2005 05:23:33
 
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01013756
Message ID:
01014184
Views:
17
>Hmmm.
>
>Interestingly enough, it seems I never did a good test. Adding some delay in the Destroy() makes the Remove(-1) method be slightly faster than re-creating the collection.
>
>
>DECLARE Sleep IN WIN32API integer
>clear
>lnLen = 1000
>el=SET("Eventlist")
>
>SET EVENTLIST TO init,Destroy
>SET EVENTTRACKING TO SYS(2023)+'\track.log'
>SET EVENTTRACKING ON
>
>lnStart=Seconds()
>loCollection = Createobject("collection")
>FOR k=1 TO lnLen
>	loCollection.Add(CREATEOBJECT("myException", 15), 'C1_'+TRANSFORM(m.k))
>NEXT
>lnStart=Seconds()
>loCollection.Remove(-1)
>? 'Remove: ', Seconds() - lnStart
>release loCollection
>
>loCollection = Createobject("collection")
>FOR k=1 TO lnLen
>	loCollection.Add(CREATEOBJECT("myException", 15), 'C2_'+TRANSFORM(m.k))
>NEXT
>lnStart=Seconds()
>loCollection = Createobject("collection")
>? 'Create: ', Seconds() - lnStart
>release loCollection
>
>SET EVENTTRACKING OFF
>SET EVENTTRACKING TO
>SET EVENTLIST TO &el
>
>MODIFY FILE SYS(2023)+'\track.log'
>ERASE SYS(2023)+'\track.log'
>
>DEFINE CLASS myException as Exception
>	PROTECTED nSleep
>	PROCEDURE init(tnSleep)
>		this.nSleep = IIF(VARTYPE(tnSleep)='N' and tnSleep > 0, tnSleep, 1)
>	ENDPROC
>	
>	PROCEDURE destroy
>		sleep(this.nSleep)
>	ENDPROC
>ENDDEFINE
>
>
>Actually, it apparently it also depends on the object, I ran this with differnt objects
>
>Line, CreateObject is faster
>myLine, CreateObject is faster
>Number (Rand()), Remove is slightly faster
>mySession, CreateObject is slightly faster
>Session, CreateObject is much faster...
>
>I guess that overall I still preferr to always use CreateObject, if I am not missing something, of course

Hi Hugo,
with large collections, the difference is not meaningful.

But:

1. If collection is little, create/destroy it require time
clear
lnLen = 20000
lnItems = 5	&& 

PRIVATE loCollection
loCollection = null

LOCAL lnFill1 ,lnRemove1,lnFill2 ,lnRemove2

? "REMOVE"		, testRemove()

* heap monitor can work
waittime()

* try with release
? "RELEASE"		, testRelease()


PROCEDURE waittime
* heap monitor can work
lnStart=datetime()+2
DO WHILE DATETIME()<lnStart
	DOEVENTS FORCE
ENDDO

PROCEDURE testRemove

FOR JK=1 TO 10000000
NEXT

lnStart=Seconds()
loCollection = Createobject("collection")
FOR k=1 TO lnLen
	FOR j=1 TO lnItems
		=loCollection.Add(.F.)
	NEXT
	loCollection.REMOVE(-1)
NEXT
loCollection = NULL
return Seconds() - lnStart

PROCEDURE testRelease
FOR JK=1 TO 1000000
NEXT

lnStart=Seconds()
FOR k=1 TO lnLen
	loCollection = Createobject("collection")
	FOR j=1 TO lnItems
		=loCollection.Add(.F.)
	NEXT
	loCollection = NULL
NEXT
return Seconds() - lnStart
2. More important:
if it is required a persistent collection.
as an example why it have many references,
is not possible to use release.
Previous
Reply
Map
View

Click here to load this message in the networking platform