lean4-htt/tests/bench/qsort/Main.lean
Kim Morrison 3ee2842e77
feat: remove runtime bounds checks and partial from qsort (#6241)
This PR refactors `Array.qsort` to remove runtime array bounds checks,
and avoids the use of `partial`. We use the `Vector` API, along with
auto_params, to avoid having to write any proofs. The new code
benchmarks indistinguishably from the old.
2024-12-01 06:26:00 +00:00

15 lines
436 B
Text

set_option linter.unusedVariables false
abbrev Elem := UInt32
def badRand (seed : Elem) : Elem :=
seed * 1664525 + 1013904223
def mkRandomArray : Nat → Elem → Array Elem → Array Elem
| 0, seed, as => as
| i+1, seed, as => mkRandomArray i (badRand seed) (as.push seed)
def main (args : List String) : IO UInt32 := do
let a := mkRandomArray 4000000 0 (Array.mkEmpty 4000000)
IO.println (a.qsort (· < ·)).size
return 0