2023-11-13 05:17:27 +00:00
|
|
|
fun time_func title f =
|
|
|
|
|
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:29:10 +00:00
|
|
|
val start_time = Time.now ()
|
2023-11-13 09:03:29 +00:00
|
|
|
val start_time = Time.toNanoseconds start_time
|
2024-03-14 23:29:10 +00:00
|
|
|
val x = f ()
|
|
|
|
|
val end_time = Time.now ()
|
2023-11-13 09:03:29 +00:00
|
|
|
val end_time = Time.toNanoseconds end_time
|
2024-03-14 23:29:10 +00:00
|
|
|
val time_diff = end_time - start_time
|
2023-11-13 05:17:27 +00:00
|
|
|
val time_diff = LargeInt.toString time_diff
|
2023-11-13 09:03:29 +00:00
|
|
|
val time_took = String.concat ["took ", time_diff, " nanoseconds\n"]
|
2023-11-13 05:17:27 +00:00
|
|
|
val _ = (print time_took)
|
|
|
|
|
in
|
|
|
|
|
x
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun run_txns arr =
|
2024-03-14 23:29:10 +00:00
|
|
|
Vector.foldl
|
2023-11-13 05:17:27 +00:00
|
|
|
(fn ((pos, del_num, ins_str), rope) =>
|
2024-03-14 23:29:10 +00:00
|
|
|
let
|
|
|
|
|
val rope =
|
|
|
|
|
if del_num > 0 then Rope.delete (pos, del_num, rope) else rope
|
|
|
|
|
val str_size = String.size ins_str
|
|
|
|
|
val rope =
|
|
|
|
|
if str_size > 0 then Rope.insert (pos, ins_str, rope) else rope
|
|
|
|
|
in
|
|
|
|
|
rope
|
|
|
|
|
end) Rope.empty arr
|
2023-11-13 05:17:27 +00:00
|
|
|
|
2024-03-14 23:29:10 +00:00
|
|
|
fun run_txns_time title arr =
|
|
|
|
|
let val f = (fn () => run_txns arr)
|
|
|
|
|
in time_func title f
|
2023-11-13 05:17:27 +00:00
|
|
|
end
|
2023-11-13 06:05:36 +00:00
|
|
|
|
2024-03-14 23:29:10 +00:00
|
|
|
fun run_to_string rope = Rope.toString rope
|
2023-11-13 09:03:29 +00:00
|
|
|
|
|
|
|
|
fun run_to_string_time title rope =
|
2024-03-14 23:29:10 +00:00
|
|
|
let val f = (fn () => run_to_string rope)
|
|
|
|
|
in time_func title f
|
2023-11-13 09:03:29 +00:00
|
|
|
end
|
|
|
|
|
|
2024-02-15 12:30:48 +00:00
|
|
|
fun run_txns_1000_times (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:29:10 +00:00
|
|
|
val start_time = Time.now ()
|
2024-02-15 19:46:40 +00:00
|
|
|
val start_time = Time.toNanoseconds start_time
|
2023-11-14 10:44:52 +00:00
|
|
|
|
|
|
|
|
val _ = run_txns arr
|
|
|
|
|
|
2024-03-14 23:29:10 +00:00
|
|
|
val end_time = Time.now ()
|
2024-02-15 19:46:40 +00:00
|
|
|
val end_time = Time.toNanoseconds end_time
|
2024-03-14 23:29:10 +00:00
|
|
|
val time_diff = end_time - start_time
|
2024-02-15 12:30:48 +00:00
|
|
|
val counter = counter + 1
|
|
|
|
|
val total = time_diff + total
|
2023-11-14 10:44:52 +00:00
|
|
|
in
|
2024-02-15 12:30:48 +00:00
|
|
|
run_txns_1000_times (counter, arr, total)
|
2023-11-14 10:44:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun write_file 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-03-14 23:29:10 +00:00
|
|
|
fun main () =
|
2023-11-13 06:05:36 +00:00
|
|
|
let
|
2024-03-14 23:29:10 +00:00
|
|
|
(* Timing benchmarks. *)
|
2024-02-15 12:30:48 +00:00
|
|
|
val start_time = LargeInt.fromInt 0
|
2024-03-14 23:29:10 +00:00
|
|
|
val _ = run_txns_1000_times (999, svelte_arr, start_time)
|
|
|
|
|
val _ = run_txns_1000_times (999, rust_arr, start_time)
|
|
|
|
|
val _ = run_txns_1000_times (999, seph_arr, start_time)
|
|
|
|
|
val _ = run_txns_1000_times (999, automerge_arr, start_time)
|
|
|
|
|
|
|
|
|
|
(* Tests that line metadata is correct; will fail if incorrect. *)
|
|
|
|
|
val svelte = run_txns svelte_arr
|
|
|
|
|
val _ = Rope.verifyLines svelte
|
2023-11-14 10:44:52 +00:00
|
|
|
|
2024-03-14 23:29:10 +00:00
|
|
|
val rust = run_txns rust_arr
|
|
|
|
|
val _ = Rope.verifyLines rust
|
2023-11-14 10:44:52 +00:00
|
|
|
|
2024-03-14 23:29:10 +00:00
|
|
|
val seph = run_txns seph_arr
|
|
|
|
|
val _ = Rope.verifyLines seph
|
2023-11-13 09:03:29 +00:00
|
|
|
|
2024-03-14 23:29:10 +00:00
|
|
|
val automerge = run_txns automerge_arr
|
|
|
|
|
val _ = Rope.verifyLines automerge
|
2023-11-13 06:05:36 +00:00
|
|
|
in
|
|
|
|
|
()
|
|
|
|
|
end
|
2024-03-14 23:29:10 +00:00
|
|
|
|
|
|
|
|
val _ = main ()
|