Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Issue: Collection.Clear(), I don't find it.
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 9
Divers
Thread ID:
01013756
Message ID:
01014161
Vues:
23
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
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform