Execution Times

In reference to the Date Loop, this is a perfect example of when using multiple <cfoutput> on a page can actually slow down the processing of page. (Every so slightly.)

Test Case 1: Loop over date for 1200 months or 100 years with one <cfoutput>. The execution time averages ~360ms.


<cfoutput>
<cfset previousMonth="">
<cfloop index="currentDate" from="#dateAdd('m',-1200,now())#" to="#now()#" step="1">
<cfif month(currentDate) neq previousMonth>
<cfset previousMonth=month(currentDate)>
<br />
#dateformat(currentDate,'mmmm yyyy')#<br />
</cfif>
#day(currentDate)#
<cfif dayofweek(currentDate) is 7>
<br />
</cfif>
</cfloop>
</cfoutput>

Test Case 2: Loop over date for 1200 months or 100 years with a >cfoutput< for each variable that needs outputed. The execution time averages ~375ms.


<cfset previousMonth="">
<cfloop index="currentDate" from="#dateAdd('m',-1200,now())#" to="#now()#" step="1">
<cfif month(currentDate) neq previousMonth>
<cfset previousMonth=month(currentDate)>
<br /><cfoutput>#dateformat(currentDate,'mmmm yyyy')</cfoutput><br />
</cfif>
<cfoutput>#day(currentDate)#</cfoutput>
<cfif dayofweek(currentDate) is 7>
<br />
</cfif>
</cfloop>

Date Loop

Just a reminder, you can loop over a date with <cfloop> as long as you step by the day.

Example:


<cfoutput>
<cfset previousMonth="">
<cfloop index="currentDate" from="#dateAdd('m',-3,now())#" to="#now()#" step="1">
<cfif month(currentDate) neq previousMonth>
<cfset previousMonth=month(currentDate)>
<br />
#dateformat(currentDate,'mmmm yyyy')<br />
</cfif>
#day(currentDate)#
<cfif dayofweek(currentDate) is 7>
<br />
</cfif>
</cfloop>
</cfoutput>
Output:
June 2008
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
July 2008
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
August 2008
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
September 2008
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16