diff --git a/bench/bro-tree.sml b/bench/bro-tree.sml index 1ee8a8a..7306e36 100644 --- a/bench/bro-tree.sml +++ b/bench/bro-tree.sml @@ -54,4 +54,14 @@ struct fun insert (str, tree) = insRoot (ins (str, tree)) + + fun exists (str, tree) = + case tree of + N0 => false + | N1 t => exists (str, t) + | N2 (l, k, r) => + if str < k then exists (str, l) + else if str > k then exists (str, r) + else true + | _ => raise Match end diff --git a/bench/build-exists-bro-tree b/bench/build-exists-bro-tree new file mode 100755 index 0000000..dbabc3e Binary files /dev/null and b/bench/build-exists-bro-tree differ diff --git a/bench/build-exists-bro-tree.mlb b/bench/build-exists-bro-tree.mlb new file mode 100644 index 0000000..1d82d8a --- /dev/null +++ b/bench/build-exists-bro-tree.mlb @@ -0,0 +1,10 @@ +$(SML_LIB)/basis/basis.mlb + +ann + "allowVectorExps true" +in + words.sml +end + +bro-tree.sml +build-exists-bro-tree.sml diff --git a/bench/build-exists-bro-tree.sml b/bench/build-exists-bro-tree.sml new file mode 100644 index 0000000..8a23b5c --- /dev/null +++ b/bench/build-exists-bro-tree.sml @@ -0,0 +1,32 @@ +structure BuildExistsBroTree = +struct + fun helpExists (pos, tree, acc) = + if pos = Vector.length WordsList.words then + acc + else + let + val word = Vector.sub (WordsList.words, pos) + val newAcc = BroTree.exists (word, tree) + val acc = newAcc orelse acc + in + helpExists (pos + 1, tree, acc) + end + + fun exists (tree) = helpExists (0, tree, true) + + fun main () = + let + val endTree = Vector.foldl BroTree.insert BroTree.empty WordsList.words + + val startTime = Time.now () + val wordsExist = exists endTree + val finishTime = Time.now () + + val searchDuration = Time.- (finishTime, startTime) + val searchDuration = Time.toString searchDuration ^ "\n" + in + print searchDuration + end +end + +val _ = BuildExistsBroTree.main () diff --git a/bench/build-exists-string-set b/bench/build-exists-string-set new file mode 100755 index 0000000..c8534e5 Binary files /dev/null and b/bench/build-exists-string-set differ diff --git a/bench/build-exists-string-set.mlb b/bench/build-exists-string-set.mlb new file mode 100644 index 0000000..af629f3 --- /dev/null +++ b/bench/build-exists-string-set.mlb @@ -0,0 +1,10 @@ +$(SML_LIB)/basis/basis.mlb + +ann + "allowVectorExps true" +in + words.sml +end + +../src/string-set.sml +build-exists-string-set.sml diff --git a/bench/build-exists-string-set.sml b/bench/build-exists-string-set.sml new file mode 100644 index 0000000..aab17e8 --- /dev/null +++ b/bench/build-exists-string-set.sml @@ -0,0 +1,33 @@ +structure BuildExistsStringSet = +struct + fun helpExists (pos, trie, acc) = + if pos = Vector.length WordsList.words then + acc + else + let + val word = Vector.sub (WordsList.words, pos) + val newAcc = StringSet.exists (word, trie) + val acc = newAcc orelse acc + in + helpExists (pos + 1, trie, acc) + end + + fun exists trie = helpExists (0, trie, true) + + fun main () = + let + val endTrie = + Vector.foldl StringSet.insert StringSet.empty WordsList.words + + val startTime = Time.now () + val wordsExist = exists endTrie + val finishTime = Time.now () + + val searchDuration = Time.- (finishTime, startTime) + val searchDuration = Time.toString searchDuration ^ "\n" + in + print searchDuration + end +end + +val _ = BuildExistsStringSet.main ()