()
| 191 | |
| 192 | |
| 193 | def main() -> None: |
| 194 | parser = argparse.ArgumentParser( |
| 195 | description="Benchmark impact of idx_mappings_src index" |
| 196 | ) |
| 197 | parser.add_argument("db_path", help="Path to the explainshell SQLite database") |
| 198 | parser.add_argument( |
| 199 | "--iterations", |
| 200 | "-n", |
| 201 | type=int, |
| 202 | default=2000, |
| 203 | help="Number of query iterations per benchmark (default: 2000)", |
| 204 | ) |
| 205 | args = parser.parse_args() |
| 206 | |
| 207 | conn = sqlite3.connect(args.db_path) |
| 208 | conn.row_factory = sqlite3.Row |
| 209 | # Match production settings |
| 210 | conn.execute("PRAGMA journal_mode=WAL") |
| 211 | conn.execute("PRAGMA cache_size=-64000") # 64MB cache |
| 212 | |
| 213 | total_mappings = conn.execute("SELECT COUNT(*) FROM mappings").fetchone()[0] |
| 214 | total_manpages = conn.execute("SELECT COUNT(*) FROM parsed_manpages").fetchone()[0] |
| 215 | print(f"Database: {args.db_path}") |
| 216 | print(f" mappings: {total_mappings:,}") |
| 217 | print(f" parsed_manpages: {total_manpages:,}") |
| 218 | print(f" iterations: {args.iterations:,}") |
| 219 | |
| 220 | sample_size = min(200, total_mappings) |
| 221 | srcs_single, srcs_multi, srcs_subcmd = collect_sample_srcs(conn, sample_size) |
| 222 | print( |
| 223 | f" sample: {len(srcs_single)} single-dst, " |
| 224 | f"{len(srcs_multi)} multi-dst, " |
| 225 | f"{len(srcs_subcmd)} subcommand" |
| 226 | ) |
| 227 | |
| 228 | # --- Without index --- |
| 229 | conn.execute("DROP INDEX IF EXISTS idx_mappings_src") |
| 230 | without = run_suite( |
| 231 | conn, |
| 232 | "WITHOUT idx_mappings_src", |
| 233 | srcs_single, |
| 234 | srcs_multi, |
| 235 | srcs_subcmd, |
| 236 | args.iterations, |
| 237 | ) |
| 238 | |
| 239 | # --- With index --- |
| 240 | conn.execute("CREATE INDEX IF NOT EXISTS idx_mappings_src ON mappings(src)") |
| 241 | with_ = run_suite( |
| 242 | conn, |
| 243 | "WITH idx_mappings_src", |
| 244 | srcs_single, |
| 245 | srcs_multi, |
| 246 | srcs_subcmd, |
| 247 | args.iterations, |
| 248 | ) |
| 249 | |
| 250 | # --- Comparison --- |
no test coverage detected