Posted to tcl by Maximus at Mon Sep 16 11:35:29 GMT 2019view raw

  1. proc RegexCache {proc key pattern} {
  2.  
  3. global regex
  4.  
  5. if {![dict exists $regex $proc $key]} {
  6. dict set regex $proc $key $pattern
  7. }
  8.  
  9. return [dict get $regex $proc $key]
  10.  
  11. }
  12.  
  13. proc NoCache {string} {
  14.  
  15. if {[regexp {^[0-9]{9,10}$} $string]} {return 1
  16. } elseif {[regexp {sh.rt} $string]} {return 2
  17. } elseif {[regexp {^Apple} $string]} {return 3
  18. } elseif {[regexp {foo} $string]} {return 4
  19. } elseif {[regexp {bye$} $string]} {return 5
  20. } elseif {[regexp {b[aecro]d} $string]} {return 6
  21. } elseif {[regexp {k[a-c2-5]m} $string]} {return 7
  22. } elseif {[regexp {codexpedia\.(com|net|org)} $string]} {return 8
  23. } elseif {[regexp {^[\d]{4}$} $string]} {return 9
  24. } elseif {[regexp {go{2,4}gle} $string]} {return 10
  25. } elseif {[regexp {go{2,}gle} $string]} {return 11
  26. } elseif {[regexp {^(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[-/.][0-9]} $string]} {return 12
  27. } elseif {[regexp {apples?} $string]} {return 13
  28. } elseif {[regexp {co*l} $string]} {return 14
  29. } elseif {[regexp {co+l} $string]} {return 15
  30. } elseif {[regexp {q(?![0-9])} $string]} {return 16
  31. } elseif {[regexp {a\.b} $string]} {return 17
  32. } elseif {[regexp {\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b} $string]} {return 18
  33. } elseif {[regexp {https?://(www\.)?[A-Za-z0-9]+\.(com|org|edu|gov|us)/?.*} $string]} {return 19
  34. } elseif {[regexp {^[0-9]{3}-[0-9]{2}-[0-9]{4}$} $string]} {return 20
  35. } elseif {[regexp {^[\\w\\-]+(\\.[\\w\\-]+)*@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$} $string]} {return 21
  36. } elseif {[regexp {^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$} $string]} {return 22
  37. } elseif {[regexp {^([\w\.*\-*]+@([\w]\.*\-*)+[a-zA-Z]{2,9}(\s*;\s*[\w\.*\-*]+@([\w]\.*\-*)+[a-zA-Z]{2,9})*)$} $string]} {return 23
  38. } elseif {[regexp {^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$} $string]} {return 24
  39. } elseif {[regexp {^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$} $string]} {return 25
  40. } elseif {[regexp {random} $string]} {return 26
  41. } elseif {[regexp {\\s+} $string]} {return 27
  42. } elseif {[regexp {pfff} $string]} {return 28
  43. } elseif {[regexp {^$} $string]} {return 29
  44. } elseif {[regexp {^[1-9]+[0-9]*$} $string]} {return 30
  45. } elseif {[regexp {(^\d*\.?\d*[0-9]+\d*$)|(^[0-9]+\d*\.\d*$)} $string]} {return 31
  46. } elseif {[regexp {^-?[0-9]{0,2}(\.[0-9]{1,2})?$|^-?(100)(\.[0]{1,2})?$} $string]} {return 32
  47. } elseif {[regexp {doooo} $string]} {return 33
  48. } elseif {[regexp {(^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)} $string]} {return 34
  49. } elseif {[regexp {.*, [A-Z][A-Z]} $string]} {return 35
  50. } elseif {[regexp {[0-9]\{5\}(-[0-9]\{4\})?} $string]} {return 36
  51. } elseif {[regexp {[0-9]\{3\}-[0-9]\{2\}-[0-9]\{4\}} $string]} {return 37
  52. } elseif {[regexp {[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}} $string]} {return 38
  53. } elseif {[regexp {[A-Z][a-z][a-z] [0-9][0-9]*, [0-9]\{4\}} $string]} {return 39
  54. } elseif {[regexp {^(\d{1,2})\/(\d{1,2})\/(\d{2}|(19|20)\d{2})$} $string]} {return 40
  55. } elseif {[regexp {test} $string]} {return 41
  56. } elseif {[regexp {bar} $string]} {return 42
  57. } elseif {[regexp {regex} $string]} {return 43
  58. } elseif {[regexp {^[a-z0-9_-]{6,18}$} $string]} {return 44
  59. } elseif {[regexp {^[a-z0-9-]+$} $string]} {return 45
  60. } elseif {[regexp {dummy} $string]} {return 46
  61. } elseif {[regexp {^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$} $string]} {return 47
  62. } elseif {[regexp {^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$} $string]} {return 48
  63. } elseif {[regexp {[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)([eE][-+]?[0-9]+)?} $string]} {return 49
  64. } elseif {[regexp {[][${}\\]} $string]} {return 50
  65. } else {
  66. return 0
  67. }
  68. }
  69.  
  70. proc Cache {string} {
  71.  
  72. if {[regexp [RegexCache Cache 1 {^[0-9]{9,10}$}] $string]} {return 1
  73. } elseif {[regexp [RegexCache Cache 2 {sh.rt}] $string]} {return 2
  74. } elseif {[regexp [RegexCache Cache 3 {^Apple}] $string]} {return 3
  75. } elseif {[regexp [RegexCache Cache 4 {foo}] $string]} {return 4
  76. } elseif {[regexp [RegexCache Cache 5 {bye$}] $string]} {return 5
  77. } elseif {[regexp [RegexCache Cache 6 {b[aecro]d}] $string]} {return 6
  78. } elseif {[regexp [RegexCache Cache 7 {k[a-c2-5]m}] $string]} {return 7
  79. } elseif {[regexp [RegexCache Cache 8 {codexpedia\.(com|net|org)}] $string]} {return 8
  80. } elseif {[regexp [RegexCache Cache 9 {^[\d]{4}$}] $string]} {return 9
  81. } elseif {[regexp [RegexCache Cache 10 {go{2,4}gle}] $string]} {return 10
  82. } elseif {[regexp [RegexCache Cache 11 {go{2,}gle}] $string]} {return 11
  83. } elseif {[regexp [RegexCache Cache 12 {^(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[-/.][0-9]}] $string]} {return 12
  84. } elseif {[regexp [RegexCache Cache 13 {apples?}] $string]} {return 13
  85. } elseif {[regexp [RegexCache Cache 14 {co*l}] $string]} {return 14
  86. } elseif {[regexp [RegexCache Cache 15 {co+l}] $string]} {return 15
  87. } elseif {[regexp [RegexCache Cache 16 {q(?![0-9])}] $string]} {return 16
  88. } elseif {[regexp [RegexCache Cache 17 {a\.b}] $string]} {return 17
  89. } elseif {[regexp [RegexCache Cache 18 {\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b}] $string]} {return 18
  90. } elseif {[regexp [RegexCache Cache 19 {https?://(www\.)?[A-Za-z0-9]+\.(com|org|edu|gov|us)/?.*}] $string]} {return 19
  91. } elseif {[regexp [RegexCache Cache 20 {^[0-9]{3}-[0-9]{2}-[0-9]{4}$}] $string]} {return 20
  92. } elseif {[regexp [RegexCache Cache 21 {^[\\w\\-]+(\\.[\\w\\-]+)*@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$}] $string]} {return 21
  93. } elseif {[regexp [RegexCache Cache 22 {^[\w-]+(\.[\w-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)*?\.[a-z]{2,6}|(\d{1,3}\.){3}\d{1,3})(:\d{4})?$}] $string]} {return 22
  94. } elseif {[regexp [RegexCache Cache 23 {^([\w\.*\-*]+@([\w]\.*\-*)+[a-zA-Z]{2,9}(\s*;\s*[\w\.*\-*]+@([\w]\.*\-*)+[a-zA-Z]{2,9})*)$}] $string]} {return 23
  95. } elseif {[regexp [RegexCache Cache 24 {^((?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))*$}] $string]} {return 24
  96. } elseif {[regexp [RegexCache Cache 25 {^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|622((12[6-9]|1[3-9][0-9])|([2-8][0-9][0-9])|(9(([0-1][0-9])|(2[0-5]))))[0-9]{10}|64[4-9][0-9]{13}|65[0-9]{14}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})*$}] $string]} {return 25
  97. } elseif {[regexp [RegexCache Cache 26 {random}] $string]} {return 26
  98. } elseif {[regexp [RegexCache Cache 27 {\\s+}] $string]} {return 27
  99. } elseif {[regexp [RegexCache Cache 28 {pfff}] $string]} {return 28
  100. } elseif {[regexp [RegexCache Cache 29 {^$}] $string]} {return 29
  101. } elseif {[regexp [RegexCache Cache 30 {^[1-9]+[0-9]*$}] $string]} {return 30
  102. } elseif {[regexp [RegexCache Cache 31 {(^\d*\.?\d*[0-9]+\d*$)|(^[0-9]+\d*\.\d*$)}] $string]} {return 31
  103. } elseif {[regexp [RegexCache Cache 32 {^-?[0-9]{0,2}(\.[0-9]{1,2})?$|^-?(100)(\.[0]{1,2})?$}] $string]} {return 32
  104. } elseif {[regexp [RegexCache Cache 33 {doooo}] $string]} {return 33
  105. } elseif {[regexp [RegexCache Cache 34 {(^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$)}] $string]} {return 34
  106. } elseif {[regexp [RegexCache Cache 35 {.*, [A-Z][A-Z]}] $string]} {return 35
  107. } elseif {[regexp [RegexCache Cache 36 {[0-9]\{5\}(-[0-9]\{4\})?}] $string]} {return 36
  108. } elseif {[regexp [RegexCache Cache 37 {[0-9]\{3\}-[0-9]\{2\}-[0-9]\{4\}}] $string]} {return 37
  109. } elseif {[regexp [RegexCache Cache 38 {[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}}] $string]} {return 38
  110. } elseif {[regexp [RegexCache Cache 39 {[A-Z][a-z][a-z] [0-9][0-9]*, [0-9]\{4\}}] $string]} {return 39
  111. } elseif {[regexp [RegexCache Cache 40 {^(\d{1,2})\/(\d{1,2})\/(\d{2}|(19|20)\d{2})$}] $string]} {return 40
  112. } elseif {[regexp [RegexCache Cache 41 {test}] $string]} {return 41
  113. } elseif {[regexp [RegexCache Cache 42 {bar}] $string]} {return 42
  114. } elseif {[regexp [RegexCache Cache 43 {regex}] $string]} {return 43
  115. } elseif {[regexp [RegexCache Cache 44 {^[a-z0-9_-]{6,18}$}] $string]} {return 44
  116. } elseif {[regexp [RegexCache Cache 45 {^[a-z0-9-]+$}] $string]} {return 45
  117. } elseif {[regexp [RegexCache Cache 46 {dummy}] $string]} {return 46
  118. } elseif {[regexp [RegexCache Cache 47 {^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$}] $string]} {return 47
  119. } elseif {[regexp [RegexCache Cache 48 {^[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?$}] $string]} {return 48
  120. } elseif {[regexp [RegexCache Cache 49 {[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)([eE][-+]?[0-9]+)?}] $string]} {return 49
  121. } elseif {[regexp [RegexCache Cache 50 {[][${}\\]}] $string]} {return 50
  122. } else {
  123. return 0
  124. }
  125. }
  126.  
  127. dict set random 1 "4RKWbHpu=J5Y@nZ2utEuWt+k!6CKQ7#PLAAkT6h4*bg7WRr-k%"
  128. dict set random 2 "G%-efHnazdJfE*vQ6n)CA*8dt4keKvxwAQG@PZztHCy#L9W7Yh"
  129. dict set random 3 "P35=5*((kzg5dCxQxq4rAXwm4xAm@wBGuU8qZPZNr%Uayz45x6"
  130. dict set random 4 "BRCxFPPxd4mw95y43JSTwR4RMwr=jK=LsM!zzmm!hr)WkvD)dK"
  131. dict set random 5 "R7^6N@W=*53RSZ6FbwKbk@Y6STwhw4yaTny7yLjp7t)JezzkYz"
  132. dict set random 6 "7ZekPMQEKJAT)GBpd^aY@a7dfB6t_%hPQ!*XzG(qy/yAQ6je@#"
  133. dict set random 7 "SBNg9!xv6bCxVS8tPgcwdub$+k9rMZd2uLUaKJ)aV#!Xqk48p@"
  134. dict set random 8 "t5BLXMBeHGWR6t@YLZGsVqfbt/fqmkN*UCTJ*hzJ*Arf@)hA8w"
  135. dict set random 9 "NEwKaWBTMRz!3=dG9=63%SrNSRw/cZ#!EYX=*X=dqMYtzc2@TR"
  136. dict set random 10 "va3LQ+q7tpWjz%KX%qMQUPP=4EqE6wzzsUpXA6h/Ue^HU^x=6w"
  137. dict set random 11 "YVRa)ud4E-R3mSyrDG-pYPbdwwATvfttmnCP!W8uy^(FAGwZ@V"
  138. dict set random 12 "E*^9=_dbvQeEEtHZ@88u9)/5_w#F3QZbWv3@YCyUz=vFr/=-E3"
  139. dict set random 13 "d9+XCM$*9unFsnpPgkzM-))C2+4+fU8_y36#wnhq/GU!#FkuY!"
  140. dict set random 14 "4dN#s7bwmpuB5m9yHFt=sszSkZ@+f=Tm-m#CXE*=h/GZFBRsE="
  141. dict set random 15 "!x#5R=Dm!4!7YrLbHVXhx_9zerPPetCn/e=Z-g%%na+8qUfdTr"
  142. dict set random 16 "P7YH5re9rA6jRA+Mc5w#L339YK^yN_Adr=*V#V7V^AEMQNjU/Y"
  143. dict set random 17 "Eee*+/G)H47WL()jdfYuCU9^^nAuzFSy6u!//rVSURmV#+k=-j"
  144. dict set random 18 "MeNp7T+-UWF*x_Wjq_J+AhcL7M*cw9dCsAa97uV=AaF/mE/8Ng"
  145. dict set random 19 "Pm_H)BJL)ApvYwf/Eqj@8E^HxYcxXGP2Z_dSVB*_B/)GnYk2R@"
  146. dict set random 20 "M#Fmrtc(gxdKU3E^EfbM=5A/Dsxea_PKz@69E8/xu6H6h%JY=e"
  147. dict set random 21 "/)3CJ#yMQqvVfnPPzukeHt-7A#RsR3z4CjvBa74b8MEPne%hHh"
  148. dict set random 22 "J89(f^RPaPMNaxyXa56-gdsdhaJWucD@vyYWvMkEpb)RdG=yL9"
  149. dict set random 23 "BN-Sfm2ZF(fJnwEHTk=m!%XdUDrbcuMFv#FNCL#w6H@@gQ5#/4"
  150. dict set random 24 "UhQLLM8-DQSt*f5Qyr!9Z2fMZ/@dN)GQ^__j@n/YmRMauQV#Py"
  151. dict set random 25 "CH@HrJZBUvK!5JWQaeMn%f#nZmUM3dZus=tgP@u^K3!#r$^A3x"
  152. dict set random 26 "3)ed7E=VqjS5Vu9y8#qMbBuDN9=sYS_xsd)mZhjWn!KcRfYZcx"
  153. dict set random 27 "55Py#my4dF%H8VPm2pep^8JDn*gdqv94mgGC!!@ksYa/!!NW9h"
  154. dict set random 28 "5^f!KZ@BHpUT+ngknZ3b6XKW9^/Lt/mhEbw62GRk4J5wmxCf-Z"
  155. dict set random 29 "QZw8jUhUcEES-uWxZ4z8q!M+aUx776^psB%6dUWrdmFuQ$=@wG"
  156. dict set random 30 "x8(/s55EHz=CTF6kjEurYVVRmHXjdq/-_e+NZp2@64^QkLJ2#6"
  157. dict set random 31 "@^a(q-bhcjwnL+5R!j8aFj(xpx#tk83cFk-saYD+^DH26C=Ec("
  158. dict set random 32 "*7Y#EDRw!GYrTGu*PyuEXArNU_Tj+sF)tMH*HKD!JqYr2qFtyg"
  159. dict set random 33 "c4HXkxd#3hNU^e6TAyym^%qnR!6_QJvR6uJMf6+6pFCNgwtk8S"
  160. dict set random 34 "#ctQ^*vfmW#Mj5yxdTWs(wVpsF!wX^kBw2KhsaTruGteW3gq2^"
  161. dict set random 35 "6fM@x(#TqYy6Xb-atZwHdjB*)X5_REpx^+sdCQJLz)C+6vAdFR"
  162. dict set random 36 "#lWU7n_U^5W9LLjXqMpZWH_hE7!Ta)EDDryƶv(=37*ACMtWES7"
  163. dict set random 37 "-kR.p97KPBN^ern5)t#=U3rBfa_bN/5JKL7Dhd8#DAhzQFdQF4"
  164. dict set random 38 "-UKtrCRHR(!Z_)pmHzqXr@J4-G_#D_*u8BHA/gc58JhXAnNswP"
  165. dict set random 39 "%AVMx2@THzA=Eg!sy(h7W7nY_-Mh!_AgN#sWb+n9G6)35tUPle"
  166. dict set random 40 "Q4TcW#sdj!^ud5HcVhGH2b)KH@LFXV7R(@z(6R7%9cUy=A*2d%"
  167. dict set random 41 "m79Q+XLp^csjkdxAY+!SDYTbS)Pa#K_zFY*8V!96tDNd#qhr2$"
  168. dict set random 42 "@FrHq+!/Ry2Q=_3TEVKEqfn/QSgnxw-#H4e^3am=5SQbm/geZP"
  169. dict set random 43 "^eQ%jjenTmcm(u4wn@6^LBjL5uvPN-RMNuP9+^Rr3)@6=QM4fR"
  170. dict set random 44 "ANPkYd@_#pB=-n-@dw/X2z57AZA@qfXA+w5bFa!v#_g/KtYev7"
  171. dict set random 45 "RqeR3a#t=s#aKhhCpe!%4K5/#em/q!WyJcN-(HT*GnspSwYbP*"
  172. dict set random 46 "CXdqk/uUdsxhYzyPH38/D#h8Zv%Yh-%d3vPcU6^dgxCDr6^g_p"
  173. dict set random 47 "X2XpkMsVnXWf7WD/TSRgUabk=e7MvagHseuYUW#ePYt/)k-RzA"
  174. dict set random 48 "gF9TEHkE(7/wn54BX!(UeZdhg2gsqJy4phcMbfh5AhRAnKCa=V"
  175. dict set random 49 "ZELgssER7=ffAN5N-3emrJ*(UVgMJ9Kuj_FKv9sZDAsFr#Yy%n"
  176. dict set random 50 "d=4NS=XEHq/h)a@XybHXb=D%(QYL^Xj4RR/#z(/W^/_RW6VWPv"
  177.  
  178. set regex ""
  179.  
  180. set times "1000"
  181.  
  182. for {set i 1} {$i < 51} {incr i} {
  183. puts "Results - NoCache: [time {NoCache [dict get $random $i]} $times] | Cache: [time {Cache [dict get $random $i]} $times]"
  184. }