lean4-htt/tests/compile_bench/ilean_roundtrip.lean
Garmelon 08eb78a5b2
chore: switch to new test/bench suite (#12590)
This PR sets up the new integrated test/bench suite. It then migrates
all benchmarks and some related tests to the new suite. There's also
some documentation and some linting.

For now, a lot of the old tests are left alone so this PR doesn't become
even larger than it already is. Eventually, all tests should be migrated
to the new suite though so there isn't a confusing mix of two systems.
2026-02-25 13:51:53 +00:00

48 lines
1.6 KiB
Text

import Lean.Data.Lsp
def genModuleRefs (n : Nat) : IO Lean.Lsp.ModuleRefs := do
let someLoc : Lean.Lsp.RefInfo.Location :=
.mk ⟨⟨333, 444⟩, ⟨444, 555⟩⟩ <| some "A.Reasonably.Long.ParentDecl.Name.barfoo"
let mut someUsages : Array Lean.Lsp.RefInfo.Location := #[]
for _ in [0, 200] do
someUsages := someUsages.push someLoc
let someInfo : Lean.Lsp.RefInfo := {
definition? := someLoc
usages := someUsages
}
let mut refs : Lean.Lsp.ModuleRefs := .empty
for i in *...n do
let someIdent := Lean.Lsp.RefIdent.const s!"A.Reasonably.Long.Module.Name{i}" s!"A.Reasonably.Long.Declaration.Name.foobar{i}"
refs := refs.insert someIdent someInfo
return refs
@[noinline]
def compress (refs : Lean.Lsp.ModuleRefs) : IO String := do
return Lean.Json.compress (Lean.ToJson.toJson refs)
@[noinline]
def parse (s : String) : IO (Except String Lean.Json) := do
return Lean.Json.parse s
def main (args : List String) : IO Unit := do
let n := (args[0]!).toNat!
let refs ← genModuleRefs n
let compressStartTime ← IO.monoMsNow
let s ← compress refs
let compressEndTime ← IO.monoMsNow
let compressTime : Float := (compressEndTime - compressStartTime).toFloat / 1000.0
IO.println s!"measurement: compress {compressTime} s"
let parseStartTime ← IO.monoMsNow
let r ← parse s
let parseEndTime ← IO.monoMsNow
let parseTime : Float := (parseEndTime - parseStartTime).toFloat / 1000.0
match r with
| .ok _ =>
IO.println s!"measurement: parse {parseTime} s"
| .error _ =>
IO.println s!"measurement: parse {parseTime} s"
IO.println "error"