Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
New WEEKDAYS function.
Message
De
20/08/2003 17:40:08
Mike Yearwood
Toronto, Ontario, Canada
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00821896
Message ID:
00822028
Vues:
28
Hey Mark

Please try the speed trials with the McCasland-inspired <g> version I just posted!

>I am thinking you made my point. Your time results of 5.x seconds for each loop, and each loop calls the Weekdays function 100,000 times. The "slow" way was 4/10ths of a second slower over 100,000 calls. On my PC, the difference was 1/10th of a second on a Pentium4 1.8GHz with 512MB RAM.
>
>>
>>LOCAL lntotaltime,iloops,idates,idays,icycle
>>
>>FOR icycle=1 TO 2
>>	lntotaltime=0
>>
>>	?IIF(icycle=1,'Legible','Faster')+" Started time:"+TRANSFORM(TIME())
>>
>>	FOR iloops = 1 TO 10
>>		lnstarttime=SECONDS()
>>
>>		FOR idates = 1 TO 100000
>>			ldfrom=DATE()-(RAND()*50000)
>>			ldto=ldfrom+(RAND()*50000)
>>
>>			idays=weekdays(ldfrom,ldto,(icycle=1))
>>
>>		ENDFOR
>>		
>>		lnendtime=SECONDS()
>>		?SPACE(0)
>>		?"Loop "+TRANSFORM(iloops) ;
>                   +" Elapsed time in seconds:"+TRANSFORM(lnendtime-lnstarttime)
>>		lntotaltime=lntotaltime+(lnendtime-lnstarttime)
>>	ENDFOR
>>	?IIF(icycle=1,'Legible','Faster')+"Average per loop:"+TRANSFORM(lntotaltime/10)
>>
>>ENDFOR
>>
>>
>>FUNCTION weekdays
>>	LPARAMETERS tdFrom, tdTo, tllegible
>>
>>	IF VARTYPE(m.tdFrom)#"D" OR VARTYPE(m.tdTo)#"D"
>>		RETURN .F.
>>	ENDIF
>>
>>	LOCAL ldfrom, ldto, lnDOWFrom, lnDOWTo,lnstep1,lnstep2,lnstep3
>>	ldfrom = MIN(m.tdFrom,m.tdTo)
>>	ldto = MAX(m.tdFrom,m.tdTo)
>>
>>	lnDOWFrom = DOW(m.ldfrom,1)
>>	lnDOWTo = DOW(m.ldto,1)
>>
>>	IF tllegible
>>		lnstep1 = INT(((m.ldto + IIF(m.lnDOWTo >= 2,7 - m.lnDOWTo,-1));
>>			- (m.ldfrom - IIF(m.lnDOWFrom <= 6,m.lnDOWFrom - 1,0)) + 1) * 5 / 7)
>>		lnstep2 = IIF(m.lnDOWFrom >= 2 AND m.lnDOWFrom <= 6,m.lnDOWFrom - 2,0)	
>>		lnstep3 = IIF(m.lnDOWTo >= 2 AND m.lnDOWTo <= 6,6 - m.lnDOWTo,0)
>>
>>		RETURN lnstep1 - lnstep2 - lnstep3
>>	ELSE
>>		RETURN INT(((m.ldto + IIF(m.lnDOWTo >= 2,7 - m.lnDOWTo,-1));
>>			- (m.ldfrom - IIF(m.lnDOWFrom <= 6,m.lnDOWFrom - 1,0)) + 1) * 5 / 7) ;
>>			- IIF(m.lnDOWFrom >= 2 AND m.lnDOWFrom <= 6,m.lnDOWFrom - 2,0) ;
>>			- IIF(m.lnDOWTo >= 2 AND m.lnDOWTo <= 6,6 - m.lnDOWTo,0)
>>	ENDIF
>>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform