2024-05-21 15:43:22 +01:00
|
|
|
fun timeFun title f =
|
2023-11-13 05:17:27 +00:00
|
|
|
let
|
2024-03-14 23:29:10 +00:00
|
|
|
val title = String.concat ["Starting ", title, "..."]
|
2023-11-13 05:17:27 +00:00
|
|
|
val _ = (print title)
|
2024-03-14 23:35:13 +00:00
|
|
|
val startTime = Time.now ()
|
|
|
|
|
val startTime = Time.toNanoseconds startTime
|
2024-03-14 23:29:10 +00:00
|
|
|
val x = f ()
|
2024-03-14 23:35:13 +00:00
|
|
|
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)
|
2023-11-13 05:17:27 +00:00
|
|
|
in
|
|
|
|
|
x
|
|
|
|
|
end
|
|
|
|
|
|
2024-03-14 23:35:13 +00:00
|
|
|
fun runTxns arr =
|
2024-03-14 23:29:10 +00:00
|
|
|
Vector.foldl
|
2024-03-14 23:35:13 +00:00
|
|
|
(fn ((pos, delNum, insStr), rope) =>
|
2024-03-14 23:29:10 +00:00
|
|
|
let
|
2024-03-14 23:35:13 +00:00
|
|
|
val strSize = String.size insStr
|
2024-03-14 23:29:10 +00:00
|
|
|
val rope =
|
2024-05-25 10:49:57 +01:00
|
|
|
if strSize > 0 then GapBuffer.insert (pos, insStr, rope) else rope
|
2024-03-14 23:29:10 +00:00
|
|
|
in
|
|
|
|
|
rope
|
2024-05-25 10:49:57 +01:00
|
|
|
end) GapBuffer.empty arr
|
|
|
|
|
|
|
|
|
|
fun compareTxns arr =
|
|
|
|
|
Vector.foldli (fn (idx, (pos, delNum, insStr), (rope, gapBuffer)) =>
|
|
|
|
|
let
|
|
|
|
|
val strSize = String.size insStr
|
|
|
|
|
|
|
|
|
|
val rope = if strSize > 0 then TinyRope.insert (pos, insStr, rope) else
|
|
|
|
|
rope
|
|
|
|
|
val gapBuffer = if strSize > 0 then GapBuffer.insert (pos, insStr,
|
|
|
|
|
gapBuffer) else gapBuffer
|
|
|
|
|
|
|
|
|
|
val ropeString = TinyRope.toString rope
|
|
|
|
|
val gapBufferString = GapBuffer.toString gapBuffer
|
|
|
|
|
in
|
|
|
|
|
if ropeString = gapBufferString then
|
|
|
|
|
(rope, gapBuffer)
|
|
|
|
|
else
|
|
|
|
|
let
|
|
|
|
|
val _ = print ("difference detected at txn number: " ^ (Int.toString idx) ^ "\n")
|
|
|
|
|
val _ = print "rope string: \n"
|
|
|
|
|
val _ = print (ropeString ^ "\n")
|
|
|
|
|
val _ = print "gap string: \n"
|
|
|
|
|
val _ = print (gapBufferString ^ "\n")
|
|
|
|
|
val _ = raise Empty
|
|
|
|
|
in
|
|
|
|
|
(rope, gapBuffer)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
) (TinyRope.empty, GapBuffer.empty) arr
|
2023-11-13 05:17:27 +00:00
|
|
|
|
2024-03-14 23:35:13 +00:00
|
|
|
fun runTxnsTime title arr =
|
|
|
|
|
let val f = (fn () => runTxns arr)
|
|
|
|
|
in timeFun title f
|
2023-11-13 05:17:27 +00:00
|
|
|
end
|
2023-11-13 06:05:36 +00:00
|
|
|
|
2024-05-25 10:49:57 +01:00
|
|
|
fun runToString rope = GapBuffer.toString rope
|
2023-11-13 09:03:29 +00:00
|
|
|
|
2024-03-14 23:35:13 +00:00
|
|
|
fun runToStringTime title rope =
|
|
|
|
|
let val f = (fn () => runToString rope)
|
|
|
|
|
in timeFun title f
|
2023-11-13 09:03:29 +00:00
|
|
|
end
|
|
|
|
|
|
2024-03-14 23:35:13 +00:00
|
|
|
fun runTxns1000Times (counter, arr, total) =
|
2023-11-14 10:44:52 +00:00
|
|
|
if counter = 1000 then
|
2024-02-15 12:30:48 +00:00
|
|
|
let
|
|
|
|
|
val divisor = Int.toLarge 1000
|
|
|
|
|
val total = total div divisor
|
|
|
|
|
val str = LargeInt.toString total
|
|
|
|
|
in
|
2024-02-15 19:46:40 +00:00
|
|
|
print (str ^ "\n")
|
2024-02-15 12:30:48 +00:00
|
|
|
end
|
2023-11-14 10:44:52 +00:00
|
|
|
else
|
|
|
|
|
let
|
2024-03-14 23:35:13 +00:00
|
|
|
val startTime = Time.now ()
|
|
|
|
|
val startTime = Time.toNanoseconds startTime
|
2023-11-14 10:44:52 +00:00
|
|
|
|
2024-03-14 23:35:13 +00:00
|
|
|
val _ = runTxns arr
|
2023-11-14 10:44:52 +00:00
|
|
|
|
2024-03-14 23:35:13 +00:00
|
|
|
val endTime = Time.now ()
|
|
|
|
|
val endTime = Time.toNanoseconds endTime
|
|
|
|
|
val timeDiff = endTime - startTime
|
2024-02-15 12:30:48 +00:00
|
|
|
val counter = counter + 1
|
2024-03-14 23:35:13 +00:00
|
|
|
val total = timeDiff + total
|
2023-11-14 10:44:52 +00:00
|
|
|
in
|
2024-03-14 23:35:13 +00:00
|
|
|
runTxns1000Times (counter, arr, total)
|
2023-11-14 10:44:52 +00:00
|
|
|
end
|
|
|
|
|
|
2024-03-14 23:35:13 +00:00
|
|
|
fun writeFile filename acc =
|
2024-03-14 23:29:10 +00:00
|
|
|
let
|
2023-11-14 10:44:52 +00:00
|
|
|
val str = String.concatWith "," acc
|
|
|
|
|
val fd = TextIO.openOut filename
|
|
|
|
|
val _ = TextIO.output (fd, str) handle e => (TextIO.closeOut fd; raise e)
|
|
|
|
|
val _ = TextIO.closeOut fd
|
|
|
|
|
in
|
|
|
|
|
()
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-21 17:21:09 +01:00
|
|
|
fun write (fileName, rope) =
|
|
|
|
|
let
|
2024-05-25 10:49:57 +01:00
|
|
|
val str = GapBuffer.toString rope
|
2024-05-21 17:21:09 +01:00
|
|
|
val io = TextIO.openOut fileName
|
|
|
|
|
val _ = TextIO.output (io, str)
|
|
|
|
|
val _ = TextIO.closeOut io
|
|
|
|
|
in
|
|
|
|
|
()
|
|
|
|
|
end
|
|
|
|
|
|
2024-05-25 10:49:57 +01:00
|
|
|
fun loop () = loop()
|
|
|
|
|
|
2024-05-21 15:43:22 +01:00
|
|
|
fun main () =
|
2023-11-13 06:05:36 +00:00
|
|
|
let
|
2024-05-21 15:43:22 +01:00
|
|
|
(* Timing benchmarks. *)
|
2024-05-25 10:49:57 +01:00
|
|
|
val _ = compareTxns SvelteComponent.txns
|
|
|
|
|
|
2024-05-21 17:21:09 +01:00
|
|
|
val startTime = LargeInt.fromInt 0
|
2024-05-25 10:49:57 +01:00
|
|
|
val _ = runTxns1000Times (999, SvelteComponent.txns, startTime)
|
2024-05-21 15:43:22 +01:00
|
|
|
val _ = runTxns1000Times (999, rust_arr, startTime)
|
|
|
|
|
val _ = runTxns1000Times (999, seph_arr, startTime)
|
|
|
|
|
val _ = runTxns1000Times (999, automerge_arr, startTime)
|
2024-03-14 23:29:10 +00:00
|
|
|
|
2024-05-21 15:43:22 +01:00
|
|
|
(* Tests that line metadata is correct; will fail if incorrect. *)
|
2024-05-25 10:49:57 +01:00
|
|
|
val svelte = runTxns SvelteComponent.txns
|
2024-05-21 15:43:22 +01:00
|
|
|
val rust = runTxns rust_arr
|
|
|
|
|
val seph = runTxns seph_arr
|
|
|
|
|
val automerge = runTxns automerge_arr
|
2024-05-21 17:21:09 +01:00
|
|
|
|
|
|
|
|
(*
|
|
|
|
|
val _ = Rope.verifyLines svelte
|
|
|
|
|
val _ = Rope.verifyLines rust
|
|
|
|
|
val _ = Rope.verifyLines seph
|
|
|
|
|
val _ = Rope.verifyLines automerge
|
|
|
|
|
*)
|
|
|
|
|
|
2024-05-25 10:49:57 +01:00
|
|
|
val _ = write ("svelte_gap.txt", svelte)
|
|
|
|
|
val _ = write ("rust23_gap.txt", rust)
|
|
|
|
|
val _ = write ("seph23_gap.txt", seph)
|
|
|
|
|
val _ = write ("automerge_gap.txt", automerge)
|
2023-11-13 06:05:36 +00:00
|
|
|
in
|
2024-05-25 10:49:57 +01:00
|
|
|
loop ()
|
2023-11-13 06:05:36 +00:00
|
|
|
end
|
2024-03-14 23:29:10 +00:00
|
|
|
|
|
|
|
|
val _ = main ()
|