Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

TestCase_Performance.asp 7.6KB

8 miesięcy temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <%
  2. Const SMALL_SIZE = 10
  3. Const MEDIUM_SIZE = 100
  4. Const LARGE_SIZE = 1000
  5. Const EXTREME_SIZE = 10000
  6. Class Performance_Tests
  7. Public Sub Setup : End Sub
  8. Public Sub Teardown : End Sub
  9. Private m_output
  10. Private Sub Out(s)
  11. m_output = m_output & s
  12. End Sub
  13. Private Sub OutLn(s)
  14. Out s & "<br>"
  15. End Sub
  16. Private Sub Class_Initialize
  17. m_output = ""
  18. OutLn "<table width='30%'>"
  19. End Sub
  20. Private Sub Class_Terminate
  21. Out "</table>"
  22. response.write m_output
  23. End Sub
  24. Private Sub Header(s)
  25. Out "<tr><th colspan='2'><h1>" & s & "</h1></th></tr>"
  26. Out "<tr><th style='text-align: left'>Name</th><th style='text-align: left'>Duration</th></tr>"
  27. End Sub
  28. Private Sub Blank
  29. Out "<tr><td>&nbsp;</td></tr>"
  30. End Sub
  31. Private Sub Profile(name, size, start, finish)
  32. Out "<tr><td>" & name & " (" & size & " nodes)</td><td>" & Round(finish - start, 2) * 1000 & "ms</td></tr>"
  33. End Sub
  34. Public Function TestCaseNames
  35. TestCaseNames = Array("Test_LinkedList", "Test_DynamicArray", "Test_ArrayList")
  36. End Function
  37. '---------------------------------------------------------------------------------------------------------------------
  38. 'Linked List Performance Tests
  39. '---------------------------------------------------------------------------------------------------------------------
  40. Public Sub Test_LinkedList(T)
  41. Header "LinkedList_Class"
  42. LL_Push SMALL_SIZE
  43. LL_Get SMALL_SIZE
  44. LL_Remove SMALL_SIZE
  45. Blank
  46. LL_Push MEDIUM_SIZE
  47. LL_Get MEDIUM_SIZE
  48. LL_Remove MEDIUM_SIZE
  49. Blank
  50. LL_Push LARGE_SIZE
  51. LL_Get LARGE_SIZE
  52. LL_Remove LARGE_SIZE
  53. Blank
  54. LL_Push EXTREME_SIZE
  55. LL_Get EXTREME_SIZE
  56. LL_Remove EXTREME_SIZE
  57. End Sub
  58. Private Sub LL_Push(num_nodes)
  59. dim start, finish
  60. dim list : set list = new LinkedList_Class
  61. dim i
  62. start = Timer
  63. for i = 1 to num_nodes
  64. list.Push i
  65. next
  66. finish = Timer
  67. Profile "Add all nodes", num_nodes, start, finish
  68. End Sub
  69. Private Sub LL_Get(num_nodes)
  70. dim start, finish
  71. dim list : set list = new LinkedList_Class
  72. dim i
  73. start = Timer
  74. dim it : set it = list.Iterator
  75. while it.HasNext
  76. it.GetNext
  77. wend
  78. finish = Timer
  79. Profile "Get all nodes", num_nodes, start, finish
  80. End Sub
  81. Private Sub LL_Remove(num_nodes)
  82. dim start, finish
  83. dim list : set list = new LinkedList_Class
  84. dim i
  85. start = Timer
  86. while list.Count > 0
  87. list.Pop
  88. wend
  89. finish = Timer
  90. Profile "Remove all nodes", num_nodes, start, finish
  91. End Sub
  92. '---------------------------------------------------------------------------------------------------------------------
  93. 'ArrayList Performance Tests
  94. '---------------------------------------------------------------------------------------------------------------------
  95. Public Sub Test_ArrayList(T)
  96. Header ".NET ArrayList"
  97. AL_Add SMALL_SIZE
  98. AL_Get SMALL_SIZE
  99. AL_Remove SMALL_SIZE
  100. Blank
  101. AL_Add MEDIUM_SIZE
  102. AL_Get MEDIUM_SIZE
  103. AL_Remove MEDIUM_SIZE
  104. Blank
  105. AL_Add LARGE_SIZE
  106. AL_Get LARGE_SIZE
  107. AL_Remove LARGE_SIZE
  108. Blank
  109. AL_Add EXTREME_SIZE
  110. AL_Get EXTREME_SIZE
  111. AL_Remove EXTREME_SIZE
  112. End Sub
  113. Private Sub AL_Add(num_nodes)
  114. dim start, finish
  115. dim list : set list = Server.CreateObject("System.Collections.ArrayList")
  116. dim i
  117. start = Timer
  118. for i = 1 to num_nodes
  119. list.Add i
  120. next
  121. finish = Timer
  122. Profile "Add all nodes", num_nodes, start, finish
  123. End Sub
  124. Private Sub AL_Get(num_nodes)
  125. dim start, finish
  126. dim list : set list = Server.CreateObject("System.Collections.ArrayList")
  127. dim i
  128. start = Timer
  129. dim elt
  130. for each elt in list
  131. 'nop
  132. next
  133. finish = Timer
  134. Profile "Get all nodes", num_nodes, start, finish
  135. End Sub
  136. Private Sub AL_Remove(num_nodes)
  137. dim start, finish
  138. dim list : set list = Server.CreateObject("System.Collections.ArrayList")
  139. dim i
  140. start = Timer
  141. list.RemoveRange 0, list.Count
  142. finish = Timer
  143. Profile "Remove all nodes", num_nodes, start, finish
  144. End Sub
  145. '---------------------------------------------------------------------------------------------------------------------
  146. ' DynamicArray Tests
  147. '---------------------------------------------------------------------------------------------------------------------
  148. Public Sub Test_DynamicArray(T)
  149. Header "DynamicArray_Class"
  150. DA_Push SMALL_SIZE
  151. DA_Get SMALL_SIZE
  152. DA_Pop SMALL_SIZE
  153. Blank
  154. 'DA_Push MEDIUM_SIZE
  155. 'DA_Get MEDIUM_SIZE
  156. 'DA_Pop MEDIUM_SIZE
  157. '
  158. 'Blank
  159. '
  160. 'DA_Push LARGE_SIZE
  161. 'DA_Get LARGE_SIZE
  162. 'DA_Pop LARGE_SIZE
  163. '
  164. 'Blank
  165. '
  166. 'DA_Push EXTREME_SIZE
  167. 'DA_Get EXTREME_SIZE
  168. 'DA_Pop EXTREME_SIZE
  169. End Sub
  170. Private Sub DA_Push(num_nodes)
  171. dim start, finish
  172. 'dim arr : arr = array()
  173. 'redim arr(100)
  174. 'dim list : set list = DynamicArray(arr)
  175. dim list : set list = DynamicArray()
  176. dim i
  177. start = Timer
  178. for i = 1 to num_nodes
  179. list.Push i
  180. next
  181. finish = Timer
  182. Profile "Add all nodes", num_nodes, start, finish
  183. End Sub
  184. Private Sub DA_Get(num_nodes)
  185. dim start, finish
  186. dim list : set list = new DynamicArray_Class
  187. dim arr : arr = array()
  188. list.Initialize arr, 100
  189. dim i
  190. start = Timer
  191. dim it : set it = list.Iterator
  192. while it.HasNext
  193. it.GetNext
  194. wend
  195. finish = Timer
  196. Profile "Get all nodes", num_nodes, start, finish
  197. End Sub
  198. Private Sub DA_Pop(num_nodes)
  199. dim start, finish
  200. dim list : set list = new DynamicArray_Class
  201. dim arr : arr = array()
  202. list.Initialize arr, 100
  203. dim i
  204. start = Timer
  205. while list.Count > 0
  206. list.Pop
  207. wend
  208. finish = Timer
  209. Profile "Remove all nodes", num_nodes, start, finish
  210. End Sub
  211. End Class
  212. %>

Powered by TurnKey Linux.