also looking at this
Port to latest zig-master
#2
53 files
+1149
-1017
| @@ -32,12 +32,12 @@ All benchmarks run with 10,000 iterations unless otherwise noted. | ||
| 32 | 32 | |
| 33 | 33 | ### Core Operations |
| 34 | 34 | |
| 35 | | Pattern | Input | Avg Time | Ops/sec | Description | | |
| 36 | |---------|-------|----------|---------|-------------| | |
| 37 | | `hello` | `hello world` | ~6.87 µs | ~145,000 | Simple literal match | | |
| 38 | | `a+` | `aaaa` | ~5.50 µs | ~182,000 | Quantifier (one or more) | | |
| 39 | | `\d+` | `12345` | ~5.01 µs | ~200,000 | Digit character class | | |
| 40 | | `hello` (case-insensitive) | `HELLO` | ~4.62 µs | ~216,000 | Case-insensitive match | | |
| 35 | | Pattern | Input | Avg Time | Ops/sec | Description | | |
| 36 | | -------------------------- | ------------- | -------- | -------- | ------------------------ | | |
| 37 | | `hello` | `hello world` | ~6.87 µs | ~145,000 | Simple literal match | | |
| 38 | | `a+` | `aaaa` | ~5.50 µs | ~182,000 | Quantifier (one or more) | | |
| 39 | | `\d+` | `12345` | ~5.01 µs | ~200,000 | Digit character class | | |
| 40 | | `hello` (case-insensitive) | `HELLO` | ~4.62 µs | ~216,000 | Case-insensitive match | | |
| 41 | 41 | |
| 42 | 42 | ### Detailed Results |
| 43 | 43 | |
| @@ -65,24 +65,24 @@ Test 4: Case-insensitive matching... | ||
| 65 | 65 | |
| 66 | 66 | ### Time Complexity |
| 67 | 67 | |
| 68 | | Operation | Complexity | Notes | | |
| 69 | |-----------|------------|-------| | |
| 70 | | Compile | O(p) | p = pattern length | | |
| 71 | | isMatch | O(n × m) | n = input length, m = NFA states | | |
| 72 | | find | O(n × m × k) | k = starting positions attempted | | |
| 73 | | findAll | O(n × m) | Amortized over all matches | | |
| 74 | | replace | O(n + r) | r = replacement length | | |
| 75 | | replaceAll | O(n × m + r) | Includes matching cost | | |
| 76 | | split | O(n × m) | Plus array allocation | | |
| 68 | | Operation | Complexity | Notes | | |
| 69 | | ---------- | ------------ | -------------------------------- | | |
| 70 | | Compile | O(p) | p = pattern length | | |
| 71 | | isMatch | O(n × m) | n = input length, m = NFA states | | |
| 72 | | find | O(n × m × k) | k = starting positions attempted | | |
| 73 | | findAll | O(n × m) | Amortized over all matches | | |
| 74 | | replace | O(n + r) | r = replacement length | | |
| 75 | | replaceAll | O(n × m + r) | Includes matching cost | | |
| 76 | | split | O(n × m) | Plus array allocation | | |
| 77 | 77 | |
| 78 | 78 | ### Space Complexity |
| 79 | 79 | |
| 80 | | Component | Complexity | Notes | | |
| 81 | |-----------|------------|-------| | |
| 82 | | Compiled Regex (NFA) | O(p) | Persistent storage | | |
| 83 | | VM Execution | O(m × c) | c = capture group count | | |
| 84 | | Match Results | O(r) | r = number of results | | |
| 85 | | Temporary (AST) | O(p) | Freed after compilation | | |
| 80 | | Component | Complexity | Notes | | |
| 81 | | -------------------- | ---------- | ----------------------- | | |
| 82 | | Compiled Regex (NFA) | O(p) | Persistent storage | | |
| 83 | | VM Execution | O(m × c) | c = capture group count | | |
| 84 | | Match Results | O(r) | r = number of results | | |
| 85 | | Temporary (AST) | O(p) | Freed after compilation | | |
| 86 | 86 | |
| 87 | 87 | ### Greedy Matching Performance |
| 88 | 88 | |
| @@ -255,11 +255,13 @@ Pattern: "\\d{3}-\\d{4}" | ||
| 255 | 255 | ### vs. Backtracking Engines (PCRE, Python re) |
| 256 | 256 | |
| 257 | 257 | **Advantages:** |
| 258 | ||
| 258 | 259 | - ✅ **No catastrophic backtracking** - Always linear time |
| 259 | 260 | - ✅ **Predictable performance** - O(n×m) guaranteed |
| 260 | 261 | - ✅ **Memory safe** - No stack overflow on deep recursion |
| 261 | 262 | |
| 262 | 263 | **Trade-offs:** |
| 264 | ||
| 263 | 265 | - ❌ **Slower on simple patterns** - More overhead for simple cases |
| 264 | 266 | - ❌ **No backreferences** - Not currently supported |
| 265 | 267 | - ❌ **No look-around** - Not currently supported |
| @@ -267,10 +269,12 @@ Pattern: "\\d{3}-\\d{4}" | ||
| 267 | 269 | ### vs. DFA Engines (RE2, ripgrep) |
| 268 | 270 | |
| 269 | 271 | **Similarities:** |
| 272 | ||
| 270 | 273 | - ✅ **Linear time** - Both guarantee O(n×m) |
| 271 | 274 | - ✅ **No backtracking** - Deterministic matching |
| 272 | 275 | |
| 273 | 276 | **Trade-offs:** |
| 277 | ||
| 274 | 278 | - ❌ **NFA simulation** - We don't build full DFA (saves memory) |
| 275 | 279 | - ❌ **Capture groups** - Our approach is simpler for captures |
| 276 | 280 | - ✅ **Memory usage** - Lower than full DFA construction |
formatting only · 7 hidden lines
| @@ -410,6 +414,7 @@ CSV splitting (100,000 rows): ~300ms total formatting only | ||
| 410 | 414 | ``` |
| 411 | 415 | |
| 412 | 416 | These are estimates. Actual performance depends on: |
| 417 | ||
| 413 | 418 | - Pattern complexity |
| 414 | 419 | - Input characteristics |
| 415 | 420 | - Hardware specifications |