Run all benchmark queries and return stats dict.
(
conn: sqlite3.Connection,
label: str,
srcs_single: list[str],
srcs_multi: list[str],
srcs_subcmd: list[str],
iterations: int,
)
| 143 | |
| 144 | |
| 145 | def run_suite( |
| 146 | conn: sqlite3.Connection, |
| 147 | label: str, |
| 148 | srcs_single: list[str], |
| 149 | srcs_multi: list[str], |
| 150 | srcs_subcmd: list[str], |
| 151 | iterations: int, |
| 152 | ) -> dict[str, dict[str, float]]: |
| 153 | """Run all benchmark queries and return stats dict.""" |
| 154 | print(f"\n{'=' * 60}") |
| 155 | print(f" {label}") |
| 156 | print(f"{'=' * 60}") |
| 157 | |
| 158 | results: dict[str, dict[str, float]] = {} |
| 159 | |
| 160 | # Warm up the page cache |
| 161 | conn.execute("SELECT COUNT(*) FROM mappings").fetchone() |
| 162 | conn.execute("SELECT COUNT(*) FROM parsed_manpages").fetchone() |
| 163 | |
| 164 | # 1) find_man_page — single destination |
| 165 | params = [(s,) for s in srcs_single] |
| 166 | times = bench_query(conn, QUERY_FIND, params, iterations) |
| 167 | results["find_man_page (1 dst)"] = report("find_man_page (1 dst)", times) |
| 168 | |
| 169 | # 2) find_man_page — multiple destinations |
| 170 | params = [(s,) for s in srcs_multi] |
| 171 | times = bench_query(conn, QUERY_FIND, params, iterations) |
| 172 | results["find_man_page (N dst)"] = report("find_man_page (N dst)", times) |
| 173 | |
| 174 | # 3) distros_for_name |
| 175 | params = [(s,) for s in srcs_single + srcs_multi] |
| 176 | random.shuffle(params) |
| 177 | times = bench_query(conn, QUERY_DISTROS, params, iterations) |
| 178 | results["distros_for_name"] = report("distros_for_name", times) |
| 179 | |
| 180 | # 4) IN query (subcommand suggestions) |
| 181 | # Build groups of 2-5 src values to simulate real usage |
| 182 | src_pool = srcs_single + srcs_multi + srcs_subcmd |
| 183 | groups = [] |
| 184 | for _ in range(max(iterations, 200)): |
| 185 | k = random.randint(2, min(5, len(src_pool))) |
| 186 | groups.append(random.sample(src_pool, k)) |
| 187 | times = bench_in_query(conn, groups, iterations) |
| 188 | results["suggestions IN(...)"] = report("suggestions IN(...)", times) |
| 189 | |
| 190 | return results |
| 191 | |
| 192 | |
| 193 | def main() -> None: |
no test coverage detected