Skip to content

Commit eac8d5f

Browse files
lufftwclaude
andcommitted
feat(benchmarks): Add auto-generated benchmark tables with tabulate
- Add benchmark data collection scripts (collect_benchmarks.py, collect_large_n.py) - Add table generation script using tabulate for proper column widths - Generate benchmark documentation with 127 problems, 24 large n comparisons - Update README with ASCII benchmark table showing up to 66,000x speedups - Include time and space complexity comparisons (Fast vs Slow) Key features: - Descriptive method names (e.g., "Top-down Memo" instead of "recursive") - Human-readable time formatting (5.3s instead of 5268ms) - Filtered entries with complete complexity data only - Simplified verbose complexity strings Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent dec975a commit eac8d5f

File tree

8 files changed

+4700
-10
lines changed

8 files changed

+4700
-10
lines changed

README.md

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,38 @@ quickselect 96.06ms 3/3 O(n) average time, O(1) space
6565
heap 107.34ms 3/3 O(n log k) time, O(k) space
6666
```
6767

68-
**See why algorithm complexity matters:**
68+
**Why algorithm choice matters — real data from 100+ problems:**
6969

70-
```bash
71-
python runner/test_runner.py 0011_container --all --estimate
70+
```
71+
Benchmark Results (n = 5,000)
72+
┌──────────────────────┬────────────────────────┬─────────────────────┬───────────┬───────────────────┬────────────────────┐
73+
│ Problem │ Fast │ Slow │ Speedup │ Time Complexity │ Space Complexity │
74+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
75+
│ 0010 Regex Matching │ Top-down Memo 0.08ms │ Bottom-up DP 5.3s │ 66,000× │ O(mn) vs O(mn) │ O(m*n) vs O(m*n) │
76+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
77+
│ 0044 Wildcard Match │ Greedy Backtrack 1.4ms │ 2D DP Table 10.0s │ 7,000× │ O(mn) vs O(mn) │ O(1) vs O(m*n) │
78+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
79+
│ 0011 Container Water │ Two Pointers 0.75ms │ Nested Loops 4.9s │ 7,000× │ O(n) vs O(n^2) │ O(1) vs O(1) │
80+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
81+
│ 0016 3Sum Closest │ Two Ptr+Prune 1.1ms │ Two Ptr Basic 1.4s │ 1,000× │ O(n²) vs O(n²) │ O(1) vs O(1) │
82+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
83+
│ 0001 Two Sum │ Hash Map 0.66ms │ Nested Loops 70.1ms │ 106× │ O(n) vs O(n²) │ O(n) vs O(1) │
84+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
85+
│ 0055 Jump Game │ Greedy 1.7ms │ DP Array 10.9ms │ 7× │ O(n) vs O(n^2) │ O(1) vs O(n) │
86+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
87+
│ 0033 Search Rotated │ Binary Search 0.48ms │ Linear Scan 1.1ms │ 2× │ O(log n) vs O(n) │ O(1) vs O(1) │
88+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
89+
│ 0042 Trapping Rain │ Two Pointers 1.8ms │ Prefix Arrays 3.7ms │ 2× │ O(n) vs O(n) │ O(1) vs O(n) │
90+
└──────────────────────┴────────────────────────┴─────────────────────┴───────────┴───────────────────┴────────────────────┘
7291
```
7392

74-
| n | O(n) Two Pointers | O(n²) Brute Force | Speedup |
75-
|--:|------------------:|------------------:|--------:|
76-
| 500 | 0.27ms | 554ms | **2,052x** |
77-
| 1000 | 0.52ms | 2,544ms | **4,892x** |
78-
| 5000 | 2.78ms | 68,291ms | **24,565x** |
93+
📊 [Full benchmark: 100+ problems, 300+ solutions →](docs/benchmarks.md)
7994

80-
At n=5000, the O(n) algorithm finishes in **3ms** while O(n²) takes **68 seconds**.
95+
**Try it yourself:**
8196

82-
> 📖 [More examples with interpretation guide →](docs/runner/README.md#examples-gallery)
97+
```bash
98+
python runner/test_runner.py 0011_container --all --estimate
99+
```
83100

84101
**Auto-save failing cases for debugging:**
85102

@@ -188,6 +205,7 @@ Each pattern provides Intuition + Templates. Start with intuition, use templates
188205
|:---------|:------------|
189206
| [Pattern Guides](docs/patterns/README.md) | All 25+ patterns with Intuition + Templates |
190207
| [Test Runner](docs/runner/README.md) | Testing, benchmarking, and validation |
208+
| [Benchmarks](docs/benchmarks.md) | 100+ problems compared: speedups up to 65,000x |
191209

192210
### Advanced
193211

docs/benchmark_ascii_table.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Benchmark Results (n = 5,000)
2+
┌──────────────────────┬────────────────────────┬─────────────────────┬───────────┬───────────────────┬────────────────────┐
3+
│ Problem │ Fast │ Slow │ Speedup │ Time Complexity │ Space Complexity │
4+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
5+
│ 0010 Regex Matching │ Top-down Memo 0.08ms │ Bottom-up DP 5.3s │ 66,000× │ O(mn) vs O(mn) │ O(m*n) vs O(m*n) │
6+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
7+
│ 0044 Wildcard Match │ Greedy Backtrack 1.4ms │ 2D DP Table 10.0s │ 7,000× │ O(mn) vs O(mn) │ O(1) vs O(m*n) │
8+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
9+
│ 0011 Container Water │ Two Pointers 0.75ms │ Nested Loops 4.9s │ 7,000× │ O(n) vs O(n^2) │ O(1) vs O(1) │
10+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
11+
│ 0016 3Sum Closest │ Two Ptr+Prune 1.1ms │ Two Ptr Basic 1.4s │ 1,000× │ O(n²) vs O(n²) │ O(1) vs O(1) │
12+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
13+
│ 0001 Two Sum │ Hash Map 0.66ms │ Nested Loops 70.1ms │ 106× │ O(n) vs O(n²) │ O(n) vs O(1) │
14+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
15+
│ 0055 Jump Game │ Greedy 1.7ms │ DP Array 10.9ms │ 7× │ O(n) vs O(n^2) │ O(1) vs O(n) │
16+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
17+
│ 0033 Search Rotated │ Binary Search 0.48ms │ Linear Scan 1.1ms │ 2× │ O(log n) vs O(n) │ O(1) vs O(1) │
18+
├──────────────────────┼────────────────────────┼─────────────────────┼───────────┼───────────────────┼────────────────────┤
19+
│ 0042 Trapping Rain │ Two Pointers 1.8ms │ Prefix Arrays 3.7ms │ 2× │ O(n) vs O(n) │ O(1) vs O(n) │
20+
└──────────────────────┴────────────────────────┴─────────────────────┴───────────┴───────────────────┴────────────────────┘

0 commit comments

Comments
 (0)