jamo

Test Array, Struct & List: Creation, Querying & Looping

Mar 29th, 2013
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <h1>Test ColdFusion Array, Struct & List: Creation, Querying &amp; Looping</h1>
  2. <cfsetting requestTimeout="65000">
  3. <CFPARAM name="URL.size" type="integer" default="0">
  4. <CFOUTPUT><form action="#CGI.Script_Name#" method="get">
  5. Iterations: <input type="text" name="size" value="<CFIF VAL(URL.Size)>#VAL(URL.size)#</CFIF>" size=5> <input type="submit" value="Test">
  6. </form></CFOUTPUT>
  7. <CFIF NOT VAL(URL.Size)><CFABORT></CFIF>
  8.  
  9. <CFSILENT>
  10. <CFSET Stats = {A={itemType="Array", create=0, query=0, queryVector=0, loop=0}, S={itemType="Struct", create=0, query=0, loop=0}, L={itemType="List", create=0, query=0, loop=0}, H={itemType="LinkedHashMap (case-sensitive ordered struct)", create=0, query=0, loop=0}}>
  11.  
  12. <CFSET A = ArrayNew(1)>
  13. <CFSET S = StructNew()>
  14. <CFSET L = "">
  15. <CFSET H = CreateObject("java", "java.util.LinkedHashMap").init()>
  16.  
  17. <!--- Create --->
  18. <CFLOOP FROM="1" TO="#VAL(URL.Size)#" INDEX="this">
  19.     <CFSET U = createUuid()>
  20.     <CFSET Start = GetTickCount()>
  21.         <CFSET ArrayAppend(A, U)>
  22.     <CFSET Stats["A"].Create = Stats["A"].Create + (GetTickCount() - Start)>
  23.     <CFSET Start = GetTickCount()>
  24.         <CFSET S[U]="">
  25.     <CFSET Stats["S"].Create = Stats["S"].Create + (GetTickCount() - Start)>
  26.     <CFSET Start = GetTickCount()>
  27.         <CFSET L = ListAppend(L, U)>
  28.     <CFSET Stats["L"].Create = Stats["L"].Create + (GetTickCount() - Start)>
  29.     <CFSET Start = GetTickCount()>
  30.         <CFSET H[U]="">
  31.     <CFSET Stats["H"].Create = Stats["H"].Create + (GetTickCount() - Start)>
  32. </CFLOOP>
  33.  
  34. <!--- Query (if exists) --->
  35. <CFLOOP ARRAY="#A#" INDEX="this">
  36.     <CFSET U = This>
  37.     <CFSET Start = GetTickCount()>
  38.         <CFSET Temp = ArrayFind(A, U)>
  39.     <CFSET Stats["A"].query = Stats["A"].query + (GetTickCount() - Start)>
  40.     <CFSET Start = GetTickCount()>
  41.         <CFSET Temp = A.indexOf(U)+1>
  42.     <CFSET Stats["A"].queryVector = Stats["A"].queryVector + (GetTickCount() - Start)>
  43.     <CFSET Start = GetTickCount()>
  44.         <CFSET Temp = StructKeyExists(S, U)>
  45.     <CFSET Stats["S"].query = Stats["S"].query + (GetTickCount() - Start)>
  46.     <CFSET Start = GetTickCount()>
  47.         <CFSET Temp = StructKeyExists(H, U)>
  48.     <CFSET Stats["H"].query = Stats["H"].query + (GetTickCount() - Start)>
  49.     <CFSET Start = GetTickCount()>
  50.         <CFSET Temp = ListFind(L, U)>
  51.     <CFSET Stats["L"].query = Stats["L"].query + (GetTickCount() - Start)>
  52. </CFLOOP>
  53.  
  54. <!--- Loop --->
  55. <CFSET Start = GetTickCount()>
  56. <CFLOOP ARRAY="#A#" INDEX="this"></CFLOOP>
  57. <CFSET Stats["A"].Loop = Stats["A"].Loop + (GetTickCount() - Start)>
  58.  
  59. <CFSET Start = GetTickCount()>
  60. <CFLOOP COLLECTION="#S#" ITEM="this"></CFLOOP>
  61. <CFSET Stats["S"].Loop = Stats["S"].Loop + (GetTickCount() - Start)>
  62.  
  63. <CFSET Start = GetTickCount()>
  64. <CFLOOP COLLECTION="#H#" ITEM="this"></CFLOOP>
  65. <CFSET Stats["H"].Loop = Stats["H"].Loop + (GetTickCount() - Start)>
  66.  
  67. <CFSET Start = GetTickCount()>
  68. <CFLOOP LIST="#L#" INDEX="this"></CFLOOP>
  69. <CFSET Stats["L"].Loop = Stats["L"].Loop + (GetTickCount() - Start)>
  70. </CFSILENT>
  71.  
  72. <CFOUTPUT><p>Executed at: #Now()#</p></CFOUTPUT>
  73. <table>
  74. <tr valign="top"><CFLOOP LIST="A,L,S,H" INDEX="this"><td><CFDUMP VAR="#Stats[this]#" Label="#Stats[this].ItemType#"></td></CFLOOP></tr>
  75. </table>
Advertisement
Add Comment
Please, Sign In to add comment