change utils.sml to use camelCase (except for svelte_arr/rust_arr/seph_arr/automerge_arr, because I don't want to create a diff for large files

This commit is contained in:
2024-03-14 23:35:13 +00:00
parent f5649b4ee9
commit a7417d89af

View File

@@ -1,46 +1,45 @@
fun time_func title f = fun timeFun title f =
let let
val title = String.concat ["Starting ", title, "..."] val title = String.concat ["Starting ", title, "..."]
val _ = (print title) val _ = (print title)
val start_time = Time.now () val startTime = Time.now ()
val start_time = Time.toNanoseconds start_time val startTime = Time.toNanoseconds startTime
val x = f () val x = f ()
val end_time = Time.now () val endTime = Time.now ()
val end_time = Time.toNanoseconds end_time val endTime = Time.toNanoseconds endTime
val time_diff = end_time - start_time val timeDiff = endTime - startTime
val time_diff = LargeInt.toString time_diff val timeDiff = LargeInt.toString timeDiff
val time_took = String.concat ["took ", time_diff, " nanoseconds\n"] val timeTook = String.concat ["took ", timeDiff, " nanoseconds\n"]
val _ = (print time_took) val _ = (print timeTook)
in in
x x
end end
fun run_txns arr = fun runTxns arr =
Vector.foldl Vector.foldl
(fn ((pos, del_num, ins_str), rope) => (fn ((pos, delNum, insStr), rope) =>
let let
val rope = if delNum > 0 then Rope.delete (pos, delNum, rope) else rope
val strSize = String.size insStr
val rope = val rope =
if del_num > 0 then Rope.delete (pos, del_num, rope) else rope if strSize > 0 then Rope.insert (pos, insStr, 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 in
rope rope
end) Rope.empty arr end) Rope.empty arr
fun run_txns_time title arr = fun runTxnsTime title arr =
let val f = (fn () => run_txns arr) let val f = (fn () => runTxns arr)
in time_func title f in timeFun title f
end end
fun run_to_string rope = Rope.toString rope fun runToString rope = Rope.toString rope
fun run_to_string_time title rope = fun runToStringTime title rope =
let val f = (fn () => run_to_string rope) let val f = (fn () => runToString rope)
in time_func title f in timeFun title f
end end
fun run_txns_1000_times (counter, arr, total) = fun runTxns1000Times (counter, arr, total) =
if counter = 1000 then if counter = 1000 then
let let
val divisor = Int.toLarge 1000 val divisor = Int.toLarge 1000
@@ -51,21 +50,21 @@ fun run_txns_1000_times (counter, arr, total) =
end end
else else
let let
val start_time = Time.now () val startTime = Time.now ()
val start_time = Time.toNanoseconds start_time val startTime = Time.toNanoseconds startTime
val _ = run_txns arr val _ = runTxns arr
val end_time = Time.now () val endTime = Time.now ()
val end_time = Time.toNanoseconds end_time val endTime = Time.toNanoseconds endTime
val time_diff = end_time - start_time val timeDiff = endTime - startTime
val counter = counter + 1 val counter = counter + 1
val total = time_diff + total val total = timeDiff + total
in in
run_txns_1000_times (counter, arr, total) runTxns1000Times (counter, arr, total)
end end
fun write_file filename acc = fun writeFile filename acc =
let let
val str = String.concatWith "," acc val str = String.concatWith "," acc
val fd = TextIO.openOut filename val fd = TextIO.openOut filename
@@ -78,23 +77,23 @@ fun write_file filename acc =
fun main () = fun main () =
let let
(* Timing benchmarks. *) (* Timing benchmarks. *)
val start_time = LargeInt.fromInt 0 val startTime = LargeInt.fromInt 0
val _ = run_txns_1000_times (999, svelte_arr, start_time) val _ = runTxns1000Times (999, svelte_arr, startTime)
val _ = run_txns_1000_times (999, rust_arr, start_time) val _ = runTxns1000Times (999, rust_arr, startTime)
val _ = run_txns_1000_times (999, seph_arr, start_time) val _ = runTxns1000Times (999, seph_arr, startTime)
val _ = run_txns_1000_times (999, automerge_arr, start_time) val _ = runTxns1000Times (999, automerge_arr, startTime)
(* Tests that line metadata is correct; will fail if incorrect. *) (* Tests that line metadata is correct; will fail if incorrect. *)
val svelte = run_txns svelte_arr val svelte = runTxns svelte_arr
val _ = Rope.verifyLines svelte val _ = Rope.verifyLines svelte
val rust = run_txns rust_arr val rust = runTxns rust_arr
val _ = Rope.verifyLines rust val _ = Rope.verifyLines rust
val seph = run_txns seph_arr val seph = runTxns seph_arr
val _ = Rope.verifyLines seph val _ = Rope.verifyLines seph
val automerge = run_txns automerge_arr val automerge = runTxns automerge_arr
val _ = Rope.verifyLines automerge val _ = Rope.verifyLines automerge
in in
() ()