benchmark.bmx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. SuperStrict
  2. Framework brl.standardio
  3. Import brl.linkedlist
  4. Import brl.objectlist
  5. Global words:String[] = ["ring", "white", "infection", "calorie", "wage", "trust", "adventure", "ribbon", "assumption", "marble", ..
  6. "favorable", "gun", "bark", "lick", "frank", "idea", "game", "white", "generation", "perfect", "leash", "sniff", "formal", ..
  7. "hay", "pavement", "treaty", "user", "outer", "heir", "looting", "plaintiff", "welfare", "pier", "adventure", "ribbon", ..
  8. "assumption", "precision", "image", "review", "idea", "game", "white", "generation", "perfect", "move", "establish", "lamp",
  9. "fool", "ridge", "fortune", "psychology", "idea", "matter", "appearance", "fruit", "velvet", "white", "thread", "bless", "scream", "heaven"]
  10. Global sorted_words:String[] = ["adventure", "adventure", "appearance", "assumption", "assumption", "bark", "bless", "calorie", ..
  11. "establish", "favorable", "fool", "formal", "fortune", "frank", "fruit", "game", "game", "generation", "generation", "gun", ..
  12. "hay", "heaven", "heir", "idea", "idea", "idea", "image", "infection", "lamp", "leash", "lick", "looting", "marble", "matter", ..
  13. "move", "outer", "pavement", "perfect", "perfect", "pier", "plaintiff", "precision", "psychology", "review", "ribbon", "ribbon", ..
  14. "ridge", "ring", "scream", "sniff", "thread", "treaty", "trust", "user", "velvet", "wage", "welfare", "white", "white", "white", "white" ]
  15. Global reversed_words:String[] = ["white", "white", "white", "white", "welfare", "wage", "velvet", "user", "trust", "treaty", ..
  16. "thread", "sniff", "scream", "ring", "ridge", "ribbon", "ribbon", "review", "psychology", "precision", "plaintiff", "pier", ..
  17. "perfect", "perfect", "pavement", "outer", "move", "matter", "marble", "looting", "lick", "leash", "lamp", "infection", "image", ..
  18. "idea", "idea", "idea", "heir", "heaven", "hay", "gun", "generation", "generation", "game", "game", "fruit", "frank", "fortune", ..
  19. "formal", "fool", "favorable", "establish", "calorie", "bless", "bark", "assumption", "assumption", "appearance", "adventure", "adventure"]
  20. Const COUNT:Int = 10000
  21. Print "Using " + COUNT + " iterations with " + words.length + " words list :"
  22. Local log1:TTestLogger = testTList()
  23. Local log2:TTestLogger = testTObjectList()
  24. MergeLogs([log1, log2])
  25. Function testTList:TTestLogger()
  26. Local out:TTestLogger = New TTestLogger
  27. out.Print " "
  28. out.Print "TList"
  29. Local list:TList = New TList
  30. out.Print " AddLast/Clear"
  31. Local ts:Int = MilliSecs()
  32. For Local i:Int = 0 Until COUNT
  33. For Local s:String = EachIn words
  34. list.AddLast(s)
  35. Next
  36. If list.Count() <> words.length Throw "Wrong count"
  37. list.Clear()
  38. If list.Count() <> 0 Throw "Wrong count"
  39. Next
  40. Local te:Int = MilliSecs()
  41. out.Print " took " + (te - ts) + "ms"
  42. out.Print " AddFirst/Clear"
  43. ts = MilliSecs()
  44. For Local i:Int = 0 Until COUNT
  45. For Local s:String = EachIn words
  46. list.AddFirst(s)
  47. Next
  48. If list.Count() <> words.length Throw "Wrong count"
  49. list.Clear()
  50. If list.Count() <> 0 Throw "Wrong count"
  51. Next
  52. te = MilliSecs()
  53. out.Print " took " + (te - ts) + "ms"
  54. out.Print " Contains"
  55. list.Clear()
  56. For Local s:String = EachIn words
  57. list.AddLast(s)
  58. Next
  59. ts = MilliSecs()
  60. For Local i:Int = 0 Until COUNT
  61. Local total:Int
  62. For Local s:String = EachIn words
  63. If list.Contains(s) Then
  64. total :+ 1
  65. End If
  66. Next
  67. If total <> words.length Throw "Wrong count"
  68. Next
  69. te = MilliSecs()
  70. out.Print " took " + (te - ts) + "ms"
  71. out.Print " ValueAtIndex"
  72. list.Clear()
  73. For Local s:String = EachIn words
  74. list.AddLast(s)
  75. Next
  76. ts = MilliSecs()
  77. For Local i:Int = 0 Until COUNT
  78. For Local n:Int = 0 Until words.length
  79. Local s:String = String(list.ValueAtIndex(n))
  80. If s <> words[n] Then Throw "Wrong value : " + s + "/" + words[n]
  81. Next
  82. Next
  83. te = MilliSecs()
  84. out.Print " took " + (te - ts) + "ms"
  85. out.Print " First/Last"
  86. list.Clear()
  87. For Local s:String = EachIn words
  88. list.AddLast(s)
  89. Next
  90. ts = MilliSecs()
  91. For Local i:Int = 0 Until COUNT * 10
  92. If list.First() <> words[0] Then Throw "Wrong value"
  93. If list.Last() <> words[words.length - 1] Then Throw "Wrong value"
  94. Next
  95. te = MilliSecs()
  96. out.Print " took " + (te - ts) + "ms"
  97. out.Print " AddLast/RemoveFirst"
  98. ts = MilliSecs()
  99. For Local i:Int = 0 Until COUNT
  100. list.Clear()
  101. For Local s:String = EachIn words
  102. list.AddLast(s)
  103. Next
  104. For Local s:String = EachIn words
  105. Local v:String = String(list.RemoveFirst())
  106. If v <> s Then Throw "Wrong value : " + v + "/" + s
  107. Next
  108. If list.Count() <> 0 Throw "Wrong count"
  109. Next
  110. te = MilliSecs()
  111. out.Print " took " + (te - ts) + "ms"
  112. out.Print " AddLast/RemoveLast"
  113. ts = MilliSecs()
  114. For Local i:Int = 0 Until COUNT
  115. list.Clear()
  116. For Local s:String = EachIn words
  117. list.AddLast(s)
  118. Next
  119. Local n:Int = words.length - 1
  120. While n >= 0
  121. Local s:String = words[n]
  122. Local v:String = String(list.RemoveLast())
  123. If v <> s Then Throw "Wrong value : " + v + "/" + s
  124. n :- 1
  125. Wend
  126. If list.Count() <> 0 Throw "Wrong count"
  127. Next
  128. te = MilliSecs()
  129. out.Print " took " + (te - ts) + "ms"
  130. out.Print " AddLast/Contains/Remove"
  131. ts = MilliSecs()
  132. For Local i:Int = 0 Until COUNT
  133. list.Clear()
  134. For Local s:String = EachIn words
  135. list.AddLast(s)
  136. Next
  137. Local toRemove:String[] = ["white", "idea", "game"]
  138. For Local s:String = EachIn toRemove
  139. While list.Contains(s)
  140. If Not list.Remove(s) Then Throw "nothing to remove"
  141. Wend
  142. Next
  143. If list.Count() <> 52 Throw "Wrong count : " + list.Count() + "/" + 52
  144. Next
  145. te = MilliSecs()
  146. out.Print " took " + (te - ts) + "ms"
  147. out.Print " AddLast/Contains/Remove+/Compact"
  148. out.Print " n/a"
  149. out.Print " enumerating"
  150. ts = MilliSecs()
  151. list.Clear()
  152. For Local s:String = EachIn words
  153. list.AddLast(s)
  154. Next
  155. For Local i:Int = 0 Until COUNT
  156. Local n:Int
  157. For Local s:String = EachIn list
  158. Local v:String = words[n]
  159. If s <> v Then Throw "Wrong value : " + s + "/" + v
  160. n :+ 1
  161. Next
  162. Next
  163. te = MilliSecs()
  164. out.Print " took " + (te - ts) + "ms"
  165. out.Print " Clear/AddLast/enumerate/Remove"
  166. ts = MilliSecs()
  167. For Local i:Int = 0 Until COUNT
  168. list.Clear()
  169. For Local s:String = EachIn words
  170. list.AddLast(s)
  171. Next
  172. For Local s:String = EachIn list
  173. list.Remove(s)
  174. Next
  175. If list.Count() <> 0 Throw "Wrong count"
  176. Next
  177. te = MilliSecs()
  178. out.Print " took " + (te - ts) + "ms"
  179. out.Print " Reverse"
  180. list.Clear()
  181. For Local s:String = EachIn words
  182. list.AddLast(s)
  183. Next
  184. Local toggle:Int
  185. ts = MilliSecs()
  186. For Local i:Int = 0 Until COUNT * 5
  187. list.Reverse()
  188. If toggle Then
  189. If list.First() <> words[0] Throw "Wrong Value"
  190. If list.Last() <> words[words.length-1] Throw "Wrong Value"
  191. Else
  192. If list.Last() <> words[0] Throw "Wrong Value"
  193. If list.First() <> words[words.length-1] Throw "Wrong Value"
  194. End If
  195. toggle = 1 - toggle
  196. Next
  197. te = MilliSecs()
  198. out.Print " took " + (te - ts) + "ms"
  199. out.Print " Copy"
  200. list.Clear()
  201. For Local s:String = EachIn words
  202. list.AddLast(s)
  203. Next
  204. ts = MilliSecs()
  205. For Local i:Int = 0 Until COUNT
  206. Local list2:TList = list.Copy()
  207. If list2.Count() <> words.length Throw "wrong size"
  208. If list2.First() <> words[0] Throw "Wrong Value"
  209. If list2.Last() <> words[words.length-1] Throw "Wrong Value"
  210. Next
  211. te = MilliSecs()
  212. out.Print " took " + (te - ts) + "ms"
  213. out.Print " Clear/AddLast/Sort"
  214. ts = MilliSecs()
  215. For Local i:Int = 0 Until COUNT
  216. list.Clear()
  217. For Local s:String = EachIn words
  218. list.AddLast(s)
  219. Next
  220. list.Sort()
  221. Next
  222. te = MilliSecs()
  223. For Local i:Int = 0 Until sorted_words.length
  224. If String(list.ValueAtIndex(i)) <> sorted_words[i] Throw "Wrong Value"
  225. Next
  226. out.Print " took " + (te - ts) + "ms"
  227. out.Print " Clear/AddLast/Sort (reversed)"
  228. ts = MilliSecs()
  229. For Local i:Int = 0 Until COUNT
  230. list.Clear()
  231. For Local s:String = EachIn words
  232. list.AddLast(s)
  233. Next
  234. list.Sort(False)
  235. Next
  236. te = MilliSecs()
  237. For Local i:Int = 0 Until reversed_words.length
  238. If String(list.ValueAtIndex(i)) <> reversed_words[i] Throw "Wrong Value"
  239. Next
  240. out.Print " took " + (te - ts) + "ms"
  241. Return out
  242. End Function
  243. Function testTObjectList:TTestLogger()
  244. Local out:TTestLogger = New TTestLogger
  245. out.Print " "
  246. out.Print "TObjectList"
  247. Local list:TObjectList = New TObjectList
  248. out.Print " AddLast/Clear"
  249. Local ts:Int = MilliSecs()
  250. For Local i:Int = 0 Until COUNT
  251. For Local s:String = EachIn words
  252. list.AddLast(s)
  253. Next
  254. If list.Count() <> words.length Throw "Wrong count"
  255. list.Clear()
  256. If list.Count() <> 0 Throw "Wrong count"
  257. Next
  258. Local te:Int = MilliSecs()
  259. out.Print " took " + (te - ts) + "ms"
  260. out.Print " AddFirst/Clear"
  261. ts = MilliSecs()
  262. For Local i:Int = 0 Until COUNT
  263. For Local s:String = EachIn words
  264. list.AddFirst(s)
  265. Next
  266. If list.Count() <> words.length Throw "Wrong count"
  267. list.Clear()
  268. If list.Count() <> 0 Throw "Wrong count"
  269. Next
  270. te = MilliSecs()
  271. out.Print " took " + (te - ts) + "ms"
  272. out.Print " Contains"
  273. list.Clear()
  274. For Local s:String = EachIn words
  275. list.AddLast(s)
  276. Next
  277. ts = MilliSecs()
  278. For Local i:Int = 0 Until COUNT
  279. Local total:Int
  280. For Local s:String = EachIn words
  281. If list.Contains(s) Then
  282. total :+ 1
  283. End If
  284. Next
  285. If total <> words.length Throw "Wrong count"
  286. Next
  287. te = MilliSecs()
  288. out.Print " took " + (te - ts) + "ms"
  289. out.Print " ValueAtIndex"
  290. list.Clear()
  291. For Local s:String = EachIn words
  292. list.AddLast(s)
  293. Next
  294. ts = MilliSecs()
  295. For Local i:Int = 0 Until COUNT
  296. For Local n:Int = 0 Until words.length
  297. Local s:String = String(list.ValueAtIndex(n))
  298. If s <> words[n] Then Throw "Wrong value : " + s + "/" + words[n]
  299. Next
  300. Next
  301. te = MilliSecs()
  302. out.Print " took " + (te - ts) + "ms"
  303. out.Print " First/Last"
  304. list.Clear()
  305. For Local s:String = EachIn words
  306. list.AddLast(s)
  307. Next
  308. ts = MilliSecs()
  309. For Local i:Int = 0 Until COUNT * 10
  310. If list.First() <> words[0] Then Throw "Wrong value"
  311. If list.Last() <> words[words.length - 1] Then Throw "Wrong value"
  312. Next
  313. te = MilliSecs()
  314. out.Print " took " + (te - ts) + "ms"
  315. out.Print " AddLast/RemoveFirst"
  316. ts = MilliSecs()
  317. For Local i:Int = 0 Until COUNT
  318. list.Clear()
  319. For Local s:String = EachIn words
  320. list.AddLast(s)
  321. Next
  322. For Local s:String = EachIn words
  323. Local v:String = String(list.RemoveFirst())
  324. If v <> s Then Throw "Wrong value : " + v + "/" + s
  325. Next
  326. If list.Count() <> 0 Throw "Wrong count"
  327. Next
  328. te = MilliSecs()
  329. out.Print " took " + (te - ts) + "ms"
  330. out.Print " AddLast/RemoveLast"
  331. ts = MilliSecs()
  332. For Local i:Int = 0 Until COUNT
  333. list.Clear()
  334. For Local s:String = EachIn words
  335. list.AddLast(s)
  336. Next
  337. Local n:Int = words.length - 1
  338. While n >= 0
  339. Local s:String = words[n]
  340. Local v:String = String(list.RemoveLast())
  341. If v <> s Then Throw "Wrong value : " + v + "/" + s
  342. n :- 1
  343. Wend
  344. If list.Count() <> 0 Throw "Wrong count"
  345. Next
  346. te = MilliSecs()
  347. out.Print " took " + (te - ts) + "ms"
  348. out.Print " AddLast/Contains/Remove"
  349. ts = MilliSecs()
  350. For Local i:Int = 0 Until COUNT
  351. list.Clear()
  352. For Local s:String = EachIn words
  353. list.AddLast(s)
  354. Next
  355. Local toRemove:String[] = ["white", "idea", "game"]
  356. For Local s:String = EachIn toRemove
  357. While list.Contains(s)
  358. If Not list.Remove(s) Then Throw "nothing to remove"
  359. Wend
  360. Next
  361. list.Compact()
  362. If list.Count() <> 52 Throw "Wrong count : " + list.Count() + "/" + 52
  363. Next
  364. te = MilliSecs()
  365. out.Print " took " + (te - ts) + "ms"
  366. out.Print " AddLast/Contains/Remove+/Compact"
  367. ts = MilliSecs()
  368. For Local i:Int = 0 Until COUNT
  369. list.Clear()
  370. For Local s:String = EachIn words
  371. list.AddLast(s)
  372. Next
  373. Local toRemove:String[] = ["white", "idea", "game"]
  374. For Local s:String = EachIn toRemove
  375. While list.Contains(s)
  376. If Not list.Remove(s, True, False) Then Throw "nothing to remove"
  377. Wend
  378. Next
  379. If list.Count() <> 52 Throw "Wrong count : " + list.Count() + "/" + 52
  380. Next
  381. te = MilliSecs()
  382. out.Print " took " + (te - ts) + "ms"
  383. out.Print " enumerating"
  384. ts = MilliSecs()
  385. list.Clear()
  386. For Local s:String = EachIn words
  387. list.AddLast(s)
  388. Next
  389. For Local i:Int = 0 Until COUNT
  390. Local n:Int
  391. For Local s:String = EachIn list
  392. Local v:String = words[n]
  393. If s <> v Then Throw "Wrong value : " + s + "/" + v
  394. n :+ 1
  395. Next
  396. Next
  397. te = MilliSecs()
  398. out.Print " took " + (te - ts) + "ms"
  399. out.Print " Clear/AddLast/enumerate/Remove"
  400. ts = MilliSecs()
  401. For Local i:Int = 0 Until COUNT
  402. list.Clear()
  403. For Local s:String = EachIn words
  404. list.AddLast(s)
  405. Next
  406. For Local s:String = EachIn list
  407. list.Remove(s, False, False)
  408. Next
  409. If list.Count() <> 0 Throw "Wrong count"
  410. Next
  411. te = MilliSecs()
  412. out.Print " took " + (te - ts) + "ms"
  413. out.Print " Reverse"
  414. list.Clear()
  415. For Local s:String = EachIn words
  416. list.AddLast(s)
  417. Next
  418. Local toggle:Int
  419. ts = MilliSecs()
  420. For Local i:Int = 0 Until COUNT * 5
  421. list.Reverse()
  422. If toggle Then
  423. If list.First() <> words[0] Throw "Wrong Value"
  424. If list.Last() <> words[words.length-1] Throw "Wrong Value"
  425. Else
  426. If list.Last() <> words[0] Throw "Wrong Value"
  427. If list.First() <> words[words.length-1] Throw "Wrong Value"
  428. End If
  429. toggle = 1 - toggle
  430. Next
  431. te = MilliSecs()
  432. out.Print " took " + (te - ts) + "ms"
  433. out.Print " Copy"
  434. list.Clear()
  435. For Local s:String = EachIn words
  436. list.AddLast(s)
  437. Next
  438. ts = MilliSecs()
  439. For Local i:Int = 0 Until COUNT
  440. Local list2:TObjectList = list.Copy()
  441. If list2.Count() <> words.length Throw "wrong size"
  442. If list2.First() <> words[0] Throw "Wrong Value"
  443. If list2.Last() <> words[words.length-1] Throw "Wrong Value"
  444. Next
  445. te = MilliSecs()
  446. out.Print " took " + (te - ts) + "ms"
  447. out.Print " Clear/AddLast/Sort"
  448. ts = MilliSecs()
  449. For Local i:Int = 0 Until COUNT
  450. list.Clear()
  451. For Local s:String = EachIn words
  452. list.AddLast(s)
  453. Next
  454. list.Sort()
  455. Next
  456. te = MilliSecs()
  457. For Local i:Int = 0 Until sorted_words.length
  458. If String(list.ValueAtIndex(i)) <> sorted_words[i] Throw "Wrong Value"
  459. Next
  460. out.Print " took " + (te - ts) + "ms"
  461. out.Print " Clear/AddLast/Sort (reversed)"
  462. ts = MilliSecs()
  463. For Local i:Int = 0 Until COUNT
  464. list.Clear()
  465. For Local s:String = EachIn words
  466. list.AddLast(s)
  467. Next
  468. list.Sort(False)
  469. Next
  470. te = MilliSecs()
  471. For Local i:Int = 0 Until reversed_words.length
  472. If String(list.ValueAtIndex(i)) <> reversed_words[i] Throw "Wrong Value"
  473. Next
  474. out.Print " took " + (te - ts) + "ms"
  475. Return out
  476. End Function
  477. Type TTestLogger
  478. Field LINES:TList = New TList
  479. Method Print(s:String)
  480. LINES.AddLast(s)
  481. End Method
  482. End Type
  483. Function MergeLogs(logs:TTestLogger[])
  484. ' For Local n:Int = 0 Until logs.length
  485. ' Print "log " + n + " LINES = " + logs[n].LINES.count()
  486. ' Next
  487. Local widest:Int
  488. Local pad:String
  489. Local Log:TTestLogger = logs[0]
  490. Local count:Int
  491. For Local s:String = EachIn Log.LINES
  492. If s.length > widest Then
  493. widest = s.length
  494. End If
  495. count :+ 1
  496. Next
  497. For Local i:Int = 0 Until widest
  498. pad :+ " "
  499. Next
  500. For Local i:Int = 0 Until count
  501. Local s:String
  502. For Local n:Int = 0 Until logs.length
  503. Local txt:String = String(logs[n].LINES.ValueAtIndex(i))
  504. s :+ (txt + pad)[..widest + 2]
  505. Next
  506. Print s
  507. Next
  508. End Function