Skip to content

Instantly share code, notes, and snippets.

@ober
Last active February 18, 2026 21:28
Show Gist options
  • Select an option

  • Save ober/4a89b4b697387204e152246e3fd85ba3 to your computer and use it in GitHub Desktop.

Select an option

Save ober/4a89b4b697387204e152246e3fd85ba3 to your computer and use it in GitHub Desktop.
Pcre2 vs pregexp vs srfi-115

╔══════════════════════════════════════════════════════════════════════════════╗ ║ Regex Benchmark: gerbil-pcre (PCRE2+JIT) vs pregexp vs SRFI-115 ║ ╚══════════════════════════════════════════════════════════════════════════════╝

pcre2 = gerbil-pcre with PCRE2 + JIT pre = :std/pregexp (pure Scheme) sre = :std/srfi/115 (pure Scheme, SRE syntax)

us/op = microseconds per operation (lower is better)

String sizes: short = 44 chars medium = 1260 chars long = 126000 chars utf8 = 32500 chars

=== 1. Pattern Compilation ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 4.1 122499 0.508 0.025 9 pregexp 0.1 4073018 0.501 0.053 486 srfi115 0.1 4666145 0.507 0.062 583

=== 2. Literal Search (short string) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 0.4 1386140 0.506 0.051 20 pregexp 4.5 109540 0.497 0.034 316 srfi115 19.7 25516 0.502 0.010 74

=== 3. Boolean Match \d+ (short string) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 0.2 3153518 0.662 0.178 15 pregexp 0.4 1251433 0.526 0.043 360 srfi115 6.4 79466 0.510 0.008 60

=== 4. Search \d+ (medium string, ~1KB) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 4.7 108366 0.512 0.008 23 pregexp 0.4 1291255 0.502 0.037 333 srfi115 7.7 65292 0.501 0.009 62

=== 5. Search \d+ (long string, ~100KB) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 461.5 1080 0.498 0.004 9 pregexp 0.4 1301993 0.503 0.037 336 srfi115 8.1 65686 0.535 0.014 63

=== 6. Capture Groups (date YYYY-MM-DD) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 0.4 1391333 0.524 0.102 16 pregexp 5.7 91197 0.519 0.036 257 srfi115 35.5 14160 0.503 0.015 68

=== 7. Extract All \d+ (~2000 matches) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 47.2 10713 0.506 0.006 9 pregexp 4143.3 139 0.576 0.119 556 srfi115 18804.7 100 1.880 0.056 225

=== 8. Replace First (\d+ → "NUM") ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 0.7 740697 0.502 0.028 51 pregexp 5.4 92394 0.503 0.039 326 srfi115 19.7 25770 0.508 0.014 73

=== 9. Replace All \w+ → "X" (medium string) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 14.9 33694 0.503 0.005 6 pregexp 173.7 2973 0.516 0.053 382 srfi115 2117.4 241 0.510 0.013 61

=== 10. Split on comma ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 0.5 1034069 0.511 0.046 75 pregexp 10.1 50000 0.507 0.036 269 srfi115 80.8 6350 0.513 0.013 66

=== 11. Email Pattern Search ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 0.5 960125 0.519 0.050 20 pregexp 11.1 49743 0.554 0.041 261 srfi115 55.5 9059 0.503 0.008 47

=== 12. Alternation (GET|POST|DELETE) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 0.4 1252226 0.508 0.043 19 pregexp 7.4 66962 0.498 0.031 278 srfi115 39.0 12909 0.504 0.009 53

=== 13. URI Pattern /api/v\d+/\w+ (long string) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 471.7 1132 0.534 0.003 9 pregexp 44625.3 100 4.463 0.404 2799 srfi115 75135.1 100 7.514 0.228 971

=== 14. Backtracking (aaaaa*b on "aaa...a!") ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 0.3 2297343 0.701 0.152 11 pregexp 107338.9 100 10.734 1.294 10427 srfi115 425.5 1217 0.518 0.011 56

=== 15. Greedy .* Scan (".*foo" on long string) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 37.6 13115 0.493 0.006 9 pregexp 276.0 1788 0.494 0.231 595 srfi115 26240.0 100 2.624 0.066 296

=== 16. UTF-8 Search (\w+ in ~36KB UTF-8 string) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 160.5 3095 0.497 0.003 8 pregexp 0.5 948365 0.513 0.041 328 srfi115 12.5 40085 0.502 0.010 57

=== 17. UTF-8 Extract All \w+ (~36KB UTF-8 string) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 160.8 3115 0.501 0.003 8 pregexp 20231.6 100 2.023 0.439 2519 srfi115 55023.3 100 5.502 0.170 642

=== 18. Key=Value Extraction (capture groups, medium string) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 4.9 103581 0.503 0.009 22 pregexp 333.0 1515 0.504 0.042 294 srfi115 3444.4 153 0.527 0.016 69

=== 19. No-Match Search (pattern absent, long string) ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 470.3 1117 0.525 0.005 9 pregexp 31233.1 100 3.123 0.143 1011 srfi115 63012.1 100 6.301 0.294 841

=== 20. Fold — Sum All Numbers in Long String ===

Library us/op Iters Wall(s) GC(s) GCs

pcre2 456.4 1090 0.498 0.004 9 pregexp 165814.9 100 16.581 2.994 25199 srfi115 119125.3 100 11.913 0.278 1521

============================================================================== Benchmark complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment