{"id":50976848,"url":"https://github.com/somombo/time-it","last_synced_at":"2026-06-19T09:02:07.619Z","repository":{"id":362580906,"uuid":"1259819388","full_name":"somombo/time-it","owner":"somombo","description":"Lean 4 execution timer built to allow blackbox testing and programmatic inspection of elapsed time","archived":false,"fork":false,"pushed_at":"2026-06-04T22:53:34.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-05T00:11:59.543Z","etag":null,"topics":["benchmarking","blackbox","lean","lean4","monad","performance","profiling","timer","timing"],"latest_commit_sha":null,"homepage":"","language":"Lean","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/somombo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-04T22:25:53.000Z","updated_at":"2026-06-04T23:03:37.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/somombo/time-it","commit_stats":null,"previous_names":["somombo/time-it"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/somombo/time-it","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somombo%2Ftime-it","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somombo%2Ftime-it/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somombo%2Ftime-it/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somombo%2Ftime-it/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/somombo","download_url":"https://codeload.github.com/somombo/time-it/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/somombo%2Ftime-it/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34523991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-19T02:00:06.005Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["benchmarking","blackbox","lean","lean4","monad","performance","profiling","timer","timing"],"created_at":"2026-06-19T09:02:06.692Z","updated_at":"2026-06-19T09:02:07.610Z","avatar_url":"https://github.com/somombo.png","language":"Lean","funding_links":[],"categories":[],"sub_categories":[],"readme":"# time-it\n\nA monadic timing library for Lean 4.\n\n[![Lean Action CI](https://github.com/somombo/time-it/actions/workflows/lean_action_ci.yml/badge.svg)](https://github.com/somombo/time-it/actions/workflows/lean_action_ci.yml)\n\n## Motivation: Shortcomings of `IO.timeit`\n\nIn Lean 4's core library, `IO.timeit` has the following signature:\n```lean\ndef timeit (msg : String) (act : IO α) : IO α\n```\n\nWhile useful for quick debugging, it has significant limitations for building robust tools, testing performance regressions, or implementing custom profiling:\n1. **No Programmatic Access:** `IO.timeit` prints the execution duration directly to `stderr` (using `IO.eprintln`) and only returns the result `α`. This makes it impossible to inspect, log, assert against, or store the timing data programmatically.\n2. **Side Effects by Default:** It forces stdout/stderr printing, which might be undesirable in silent or structured CLI environments.\n3. **Rigid Formatting:** The output format is fixed by the Lean core library and cannot be easily customized or parsed.\n\n### The `time-it` Solution\n\nThis library provides `IO.timeAx` and `IO.timeFn`. They return the timed action's result along with the elapsed duration represented as a structured `Std.Time.Duration`:\n```lean\ndef timeAx (ax : IO α) : IO (Duration × α)\ndef timeFn (f : α → β) (x : α) : IO (Duration × β)\n```\n\nFurthermore, `time-it` utilizes a `blackBox` wrapper to prevent Lean compiler optimizations (such as dead code elimination, expression hoisting, or subexpression elimination) from optimizing away or restructuring the timed operations.\n\n---\n\n## Installation\n\nAdd `time-it` as a dependency in your `lakefile.toml`:\n\n```toml\n[[require]]\nname = \"time-it\"\ngit = \"https://github.com/somombo/time-it.git\"\nrev = \"main\"\n```\n\nThen run `lake update` to fetch the dependency.\n\n---\n\n## Usage\n\n### Timing an `IO` Action (`IO.timeAx`)\n\nTo measure how long an arbitrary `IO` computation takes:\n\n```lean\nimport TimeIt\n\ndef performComputation : IO Unit := do\n  let (duration, _) ← IO.timeAx (IO.sleep 1000) -- Sleep for 1000ms\n  IO.println s!\"The computation took {duration.toNanoseconds} ns\"\n```\n\n### Timing a Function Evaluation (`IO.timeFn`)\n\nTo measure how long a function takes to evaluate on a given input:\n\n```lean\nimport TimeIt\n\ndef main : IO Unit := do\n  let heavyComputation := fun n =\u003e (List.range n).foldl (· + ·) 0\n  let (duration, result) ← IO.timeFn heavyComputation 1000000\n  IO.println s!\"Result: {result}\"\n  IO.println s!\"Calculation took: {duration.toNanoseconds} ns\"\n```\n\n---\n\n## Development \u0026 Tests\n\nTo compile and verify the library locally:\n\n```bash\n# Build the library\nlake build\n\n# Run the test suite\nlake test\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomombo%2Ftime-it","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsomombo%2Ftime-it","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsomombo%2Ftime-it/lists"}