use joinEndOfLeft and joinStartOfRight functions to navigate between nodes in the gap buffer
This commit is contained in:
89
utils.sml
89
utils.sml
@@ -1,20 +1,3 @@
|
||||
fun timeFun title f =
|
||||
let
|
||||
val title = String.concat ["Starting ", title, "..."]
|
||||
val _ = (print title)
|
||||
val startTime = Time.now ()
|
||||
val startTime = Time.toNanoseconds startTime
|
||||
val x = f ()
|
||||
val endTime = Time.now ()
|
||||
val endTime = Time.toNanoseconds endTime
|
||||
val timeDiff = endTime - startTime
|
||||
val timeDiff = LargeInt.toString timeDiff
|
||||
val timeTook = String.concat ["took ", timeDiff, " nanoseconds\n"]
|
||||
val _ = (print timeTook)
|
||||
in
|
||||
x
|
||||
end
|
||||
|
||||
fun runTxns arr =
|
||||
Vector.foldl
|
||||
(fn ((pos, delNum, insStr), rope) =>
|
||||
@@ -26,6 +9,23 @@ fun runTxns arr =
|
||||
rope
|
||||
end) GapBuffer.empty arr
|
||||
|
||||
fun runTxnsTime arr =
|
||||
let
|
||||
val startTime = Time.now ()
|
||||
val startTime = Time.toMilliseconds startTime
|
||||
|
||||
val x = runTxns arr
|
||||
|
||||
val endTime = Time.now ()
|
||||
val endTime = Time.toMilliseconds endTime
|
||||
val timeDiff = endTime - startTime
|
||||
val timeDiff = LargeInt.toString timeDiff
|
||||
val timeTook = String.concat ["took ", timeDiff, " ms\n"]
|
||||
val _ = (print timeTook)
|
||||
in
|
||||
x
|
||||
end
|
||||
|
||||
fun compareTxns arr =
|
||||
Vector.foldli (fn (idx, (pos, delNum, insStr), (rope, gapBuffer)) =>
|
||||
let
|
||||
@@ -55,43 +55,8 @@ fun compareTxns arr =
|
||||
end
|
||||
) (TinyRope.empty, GapBuffer.empty) arr
|
||||
|
||||
fun runTxnsTime title arr =
|
||||
let val f = (fn () => runTxns arr)
|
||||
in timeFun title f
|
||||
end
|
||||
|
||||
fun runToString rope = GapBuffer.toString rope
|
||||
|
||||
fun runToStringTime title rope =
|
||||
let val f = (fn () => runToString rope)
|
||||
in timeFun title f
|
||||
end
|
||||
|
||||
fun runTxns1000Times (counter, arr, total) =
|
||||
if counter = 1000 then
|
||||
let
|
||||
val divisor = Int.toLarge 1000
|
||||
val total = total div divisor
|
||||
val str = LargeInt.toString total
|
||||
in
|
||||
print (str ^ "\n")
|
||||
end
|
||||
else
|
||||
let
|
||||
val startTime = Time.now ()
|
||||
val startTime = Time.toNanoseconds startTime
|
||||
|
||||
val _ = runTxns arr
|
||||
|
||||
val endTime = Time.now ()
|
||||
val endTime = Time.toNanoseconds endTime
|
||||
val timeDiff = endTime - startTime
|
||||
val counter = counter + 1
|
||||
val total = timeDiff + total
|
||||
in
|
||||
runTxns1000Times (counter, arr, total)
|
||||
end
|
||||
|
||||
fun writeFile filename acc =
|
||||
let
|
||||
val str = String.concatWith "," acc
|
||||
@@ -117,20 +82,24 @@ fun loop () = loop()
|
||||
fun main () =
|
||||
let
|
||||
(* Timing benchmarks. *)
|
||||
val _ = compareTxns SvelteComponent.txns
|
||||
val _ = runTxnsTime SvelteComponent.txns
|
||||
val _ = runTxnsTime rust_arr
|
||||
val _ = runTxnsTime seph_arr
|
||||
val _ = runTxnsTime automerge_arr
|
||||
|
||||
val startTime = LargeInt.fromInt 0
|
||||
val _ = runTxns1000Times (999, SvelteComponent.txns, startTime)
|
||||
val _ = runTxns1000Times (999, rust_arr, startTime)
|
||||
val _ = runTxns1000Times (999, seph_arr, startTime)
|
||||
val _ = runTxns1000Times (999, automerge_arr, startTime)
|
||||
|
||||
(* Tests that line metadata is correct; will fail if incorrect. *)
|
||||
(* Tests for correctness; will fail if incorrect. *)
|
||||
val svelte = runTxns SvelteComponent.txns
|
||||
val rust = runTxns rust_arr
|
||||
val seph = runTxns seph_arr
|
||||
val automerge = runTxns automerge_arr
|
||||
|
||||
(* Tests for insertion correctness (compare against rope). *)
|
||||
val _ = compareTxns SvelteComponent.txns
|
||||
val _ = compareTxns rust_arr
|
||||
val _ = compareTxns seph_arr
|
||||
val _ = compareTxns automerge_arr
|
||||
|
||||
(* Tests for line metadata. *)
|
||||
(*
|
||||
val _ = Rope.verifyLines svelte
|
||||
val _ = Rope.verifyLines rust
|
||||
|
||||
Reference in New Issue
Block a user