123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579 |
- SuperStrict
- Framework brl.standardio
- Import brl.linkedlist
- Import brl.objectlist
- Global words:String[] = ["ring", "white", "infection", "calorie", "wage", "trust", "adventure", "ribbon", "assumption", "marble", ..
- "favorable", "gun", "bark", "lick", "frank", "idea", "game", "white", "generation", "perfect", "leash", "sniff", "formal", ..
- "hay", "pavement", "treaty", "user", "outer", "heir", "looting", "plaintiff", "welfare", "pier", "adventure", "ribbon", ..
- "assumption", "precision", "image", "review", "idea", "game", "white", "generation", "perfect", "move", "establish", "lamp",
- "fool", "ridge", "fortune", "psychology", "idea", "matter", "appearance", "fruit", "velvet", "white", "thread", "bless", "scream", "heaven"]
- Global sorted_words:String[] = ["adventure", "adventure", "appearance", "assumption", "assumption", "bark", "bless", "calorie", ..
- "establish", "favorable", "fool", "formal", "fortune", "frank", "fruit", "game", "game", "generation", "generation", "gun", ..
- "hay", "heaven", "heir", "idea", "idea", "idea", "image", "infection", "lamp", "leash", "lick", "looting", "marble", "matter", ..
- "move", "outer", "pavement", "perfect", "perfect", "pier", "plaintiff", "precision", "psychology", "review", "ribbon", "ribbon", ..
- "ridge", "ring", "scream", "sniff", "thread", "treaty", "trust", "user", "velvet", "wage", "welfare", "white", "white", "white", "white" ]
-
- Global reversed_words:String[] = ["white", "white", "white", "white", "welfare", "wage", "velvet", "user", "trust", "treaty", ..
- "thread", "sniff", "scream", "ring", "ridge", "ribbon", "ribbon", "review", "psychology", "precision", "plaintiff", "pier", ..
- "perfect", "perfect", "pavement", "outer", "move", "matter", "marble", "looting", "lick", "leash", "lamp", "infection", "image", ..
- "idea", "idea", "idea", "heir", "heaven", "hay", "gun", "generation", "generation", "game", "game", "fruit", "frank", "fortune", ..
- "formal", "fool", "favorable", "establish", "calorie", "bless", "bark", "assumption", "assumption", "appearance", "adventure", "adventure"]
- Const COUNT:Int = 10000
- Print "Using " + COUNT + " iterations with " + words.length + " words list :"
- Local log1:TTestLogger = testTList()
- Local log2:TTestLogger = testTObjectList()
- MergeLogs([log1, log2])
- Function testTList:TTestLogger()
- Local out:TTestLogger = New TTestLogger
- out.Print " "
- out.Print "TList"
- Local list:TList = New TList
-
- out.Print " AddLast/Clear"
- Local ts:Int = MilliSecs()
- For Local i:Int = 0 Until COUNT
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- If list.Count() <> words.length Throw "Wrong count"
- list.Clear()
- If list.Count() <> 0 Throw "Wrong count"
- Next
- Local te:Int = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " AddFirst/Clear"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- For Local s:String = EachIn words
- list.AddFirst(s)
- Next
- If list.Count() <> words.length Throw "Wrong count"
- list.Clear()
- If list.Count() <> 0 Throw "Wrong count"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " Contains"
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- Local total:Int
- For Local s:String = EachIn words
- If list.Contains(s) Then
- total :+ 1
- End If
- Next
- If total <> words.length Throw "Wrong count"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " ValueAtIndex"
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- For Local n:Int = 0 Until words.length
- Local s:String = String(list.ValueAtIndex(n))
- If s <> words[n] Then Throw "Wrong value : " + s + "/" + words[n]
- Next
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " First/Last"
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT * 10
- If list.First() <> words[0] Then Throw "Wrong value"
- If list.Last() <> words[words.length - 1] Then Throw "Wrong value"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " AddLast/RemoveFirst"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- For Local s:String = EachIn words
- Local v:String = String(list.RemoveFirst())
- If v <> s Then Throw "Wrong value : " + v + "/" + s
- Next
- If list.Count() <> 0 Throw "Wrong count"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " AddLast/RemoveLast"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- Local n:Int = words.length - 1
- While n >= 0
- Local s:String = words[n]
- Local v:String = String(list.RemoveLast())
- If v <> s Then Throw "Wrong value : " + v + "/" + s
- n :- 1
- Wend
- If list.Count() <> 0 Throw "Wrong count"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " AddLast/Contains/Remove"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- Local toRemove:String[] = ["white", "idea", "game"]
- For Local s:String = EachIn toRemove
- While list.Contains(s)
- If Not list.Remove(s) Then Throw "nothing to remove"
- Wend
- Next
-
- If list.Count() <> 52 Throw "Wrong count : " + list.Count() + "/" + 52
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " AddLast/Contains/Remove+/Compact"
- out.Print " n/a"
- out.Print " enumerating"
- ts = MilliSecs()
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- For Local i:Int = 0 Until COUNT
- Local n:Int
- For Local s:String = EachIn list
- Local v:String = words[n]
- If s <> v Then Throw "Wrong value : " + s + "/" + v
- n :+ 1
- Next
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " Clear/AddLast/enumerate/Remove"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
-
- For Local s:String = EachIn list
- list.Remove(s)
- Next
- If list.Count() <> 0 Throw "Wrong count"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " Reverse"
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- Local toggle:Int
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT * 5
- list.Reverse()
- If toggle Then
- If list.First() <> words[0] Throw "Wrong Value"
- If list.Last() <> words[words.length-1] Throw "Wrong Value"
- Else
- If list.Last() <> words[0] Throw "Wrong Value"
- If list.First() <> words[words.length-1] Throw "Wrong Value"
- End If
- toggle = 1 - toggle
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " Copy"
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- Local list2:TList = list.Copy()
- If list2.Count() <> words.length Throw "wrong size"
- If list2.First() <> words[0] Throw "Wrong Value"
- If list2.Last() <> words[words.length-1] Throw "Wrong Value"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " Clear/AddLast/Sort"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- list.Sort()
-
- Next
- te = MilliSecs()
- For Local i:Int = 0 Until sorted_words.length
- If String(list.ValueAtIndex(i)) <> sorted_words[i] Throw "Wrong Value"
- Next
- out.Print " took " + (te - ts) + "ms"
- out.Print " Clear/AddLast/Sort (reversed)"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- list.Sort(False)
- Next
- te = MilliSecs()
- For Local i:Int = 0 Until reversed_words.length
- If String(list.ValueAtIndex(i)) <> reversed_words[i] Throw "Wrong Value"
- Next
- out.Print " took " + (te - ts) + "ms"
- Return out
- End Function
- Function testTObjectList:TTestLogger()
- Local out:TTestLogger = New TTestLogger
- out.Print " "
- out.Print "TObjectList"
- Local list:TObjectList = New TObjectList
-
- out.Print " AddLast/Clear"
- Local ts:Int = MilliSecs()
- For Local i:Int = 0 Until COUNT
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- If list.Count() <> words.length Throw "Wrong count"
- list.Clear()
- If list.Count() <> 0 Throw "Wrong count"
- Next
- Local te:Int = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " AddFirst/Clear"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- For Local s:String = EachIn words
- list.AddFirst(s)
- Next
- If list.Count() <> words.length Throw "Wrong count"
- list.Clear()
- If list.Count() <> 0 Throw "Wrong count"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " Contains"
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- Local total:Int
- For Local s:String = EachIn words
- If list.Contains(s) Then
- total :+ 1
- End If
- Next
- If total <> words.length Throw "Wrong count"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " ValueAtIndex"
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- For Local n:Int = 0 Until words.length
- Local s:String = String(list.ValueAtIndex(n))
- If s <> words[n] Then Throw "Wrong value : " + s + "/" + words[n]
- Next
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " First/Last"
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT * 10
- If list.First() <> words[0] Then Throw "Wrong value"
- If list.Last() <> words[words.length - 1] Then Throw "Wrong value"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " AddLast/RemoveFirst"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- For Local s:String = EachIn words
- Local v:String = String(list.RemoveFirst())
- If v <> s Then Throw "Wrong value : " + v + "/" + s
- Next
- If list.Count() <> 0 Throw "Wrong count"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " AddLast/RemoveLast"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- Local n:Int = words.length - 1
- While n >= 0
- Local s:String = words[n]
- Local v:String = String(list.RemoveLast())
- If v <> s Then Throw "Wrong value : " + v + "/" + s
- n :- 1
- Wend
- If list.Count() <> 0 Throw "Wrong count"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " AddLast/Contains/Remove"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- Local toRemove:String[] = ["white", "idea", "game"]
- For Local s:String = EachIn toRemove
- While list.Contains(s)
- If Not list.Remove(s) Then Throw "nothing to remove"
- Wend
- Next
-
- list.Compact()
-
- If list.Count() <> 52 Throw "Wrong count : " + list.Count() + "/" + 52
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " AddLast/Contains/Remove+/Compact"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- Local toRemove:String[] = ["white", "idea", "game"]
- For Local s:String = EachIn toRemove
- While list.Contains(s)
- If Not list.Remove(s, True, False) Then Throw "nothing to remove"
- Wend
- Next
-
- If list.Count() <> 52 Throw "Wrong count : " + list.Count() + "/" + 52
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " enumerating"
- ts = MilliSecs()
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- For Local i:Int = 0 Until COUNT
- Local n:Int
- For Local s:String = EachIn list
- Local v:String = words[n]
- If s <> v Then Throw "Wrong value : " + s + "/" + v
- n :+ 1
- Next
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " Clear/AddLast/enumerate/Remove"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
-
- For Local s:String = EachIn list
- list.Remove(s, False, False)
- Next
- If list.Count() <> 0 Throw "Wrong count"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " Reverse"
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- Local toggle:Int
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT * 5
- list.Reverse()
- If toggle Then
- If list.First() <> words[0] Throw "Wrong Value"
- If list.Last() <> words[words.length-1] Throw "Wrong Value"
- Else
- If list.Last() <> words[0] Throw "Wrong Value"
- If list.First() <> words[words.length-1] Throw "Wrong Value"
- End If
- toggle = 1 - toggle
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " Copy"
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- Local list2:TObjectList = list.Copy()
- If list2.Count() <> words.length Throw "wrong size"
- If list2.First() <> words[0] Throw "Wrong Value"
- If list2.Last() <> words[words.length-1] Throw "Wrong Value"
- Next
- te = MilliSecs()
- out.Print " took " + (te - ts) + "ms"
- out.Print " Clear/AddLast/Sort"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- list.Sort()
- Next
- te = MilliSecs()
- For Local i:Int = 0 Until sorted_words.length
- If String(list.ValueAtIndex(i)) <> sorted_words[i] Throw "Wrong Value"
- Next
- out.Print " took " + (te - ts) + "ms"
- out.Print " Clear/AddLast/Sort (reversed)"
- ts = MilliSecs()
- For Local i:Int = 0 Until COUNT
- list.Clear()
- For Local s:String = EachIn words
- list.AddLast(s)
- Next
- list.Sort(False)
- Next
- te = MilliSecs()
- For Local i:Int = 0 Until reversed_words.length
- If String(list.ValueAtIndex(i)) <> reversed_words[i] Throw "Wrong Value"
- Next
- out.Print " took " + (te - ts) + "ms"
- Return out
- End Function
- Type TTestLogger
- Field LINES:TList = New TList
- Method Print(s:String)
- LINES.AddLast(s)
- End Method
- End Type
- Function MergeLogs(logs:TTestLogger[])
- ' For Local n:Int = 0 Until logs.length
- ' Print "log " + n + " LINES = " + logs[n].LINES.count()
- ' Next
- Local widest:Int
- Local pad:String
- Local Log:TTestLogger = logs[0]
- Local count:Int
- For Local s:String = EachIn Log.LINES
- If s.length > widest Then
- widest = s.length
- End If
- count :+ 1
- Next
- For Local i:Int = 0 Until widest
- pad :+ " "
- Next
-
- For Local i:Int = 0 Until count
- Local s:String
- For Local n:Int = 0 Until logs.length
- Local txt:String = String(logs[n].LINES.ValueAtIndex(i))
- s :+ (txt + pad)[..widest + 2]
- Next
- Print s
- Next
- End Function
|