Created
January 22, 2023 08:47
-
-
Save trycf/60de4fc7a8a14052b56f9cc443e10aba to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
// init | |
q = queryNew( 'val' ); | |
for ( i = 1; i <= 10000; i++ ) { | |
q.addRow( {val = randRange( 1, 1000 ) } ); | |
} | |
log = [=]; | |
// reduce() | |
t = getTickCount(); | |
sum = q.reduce( function( r, row ) { | |
return r + row.val; | |
}, 0 ); | |
log['reduce'] = getTickCount() - t; | |
// each() | |
t = getTickCount(); | |
sum = 0; | |
q.each( function( row ){ | |
sum += row.val; | |
} ); | |
log['each'] = getTickCount() - t; | |
// for in | |
t = getTickCount(); | |
sum = 0; | |
for ( row in q ) { | |
sum += q.val; | |
} | |
log['for in'] = getTickCount() - t; | |
</cfscript> | |
<cfset t = getTickCount()> | |
<cfset sum = 0> | |
<cfloop query="q"> | |
<cfset sum += q.val> | |
</cfloop> | |
<cfset log['cfloop'] = getTickCount() - t> | |
<cfdump var="#log#"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment