{"id":22472244,"url":"https://github.com/ckampfe/regex_rs","last_synced_at":"2025-03-27T16:21:44.027Z","repository":{"id":72030646,"uuid":"329766313","full_name":"ckampfe/regex_rs","owner":"ckampfe","description":"Rust's Regex library as an Elixir NIF","archived":false,"fork":false,"pushed_at":"2021-10-22T06:28:29.000Z","size":33,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-01T20:11:18.437Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ckampfe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-15T00:17:36.000Z","updated_at":"2024-05-11T08:21:49.000Z","dependencies_parsed_at":"2023-03-23T09:05:11.908Z","dependency_job_id":null,"html_url":"https://github.com/ckampfe/regex_rs","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckampfe%2Fregex_rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckampfe%2Fregex_rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckampfe%2Fregex_rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ckampfe%2Fregex_rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ckampfe","download_url":"https://codeload.github.com/ckampfe/regex_rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245879022,"owners_count":20687300,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T12:13:44.143Z","updated_at":"2025-03-27T16:21:44.020Z","avatar_url":"https://github.com/ckampfe.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RegexRs\n\n[![CircleCI](https://circleci.com/gh/ckampfe/regex_rs.svg?style=svg)](https://circleci.com/gh/ckampfe/regex_rs)\n\nRust's [regex](https://crates.io/crates/regex) library as an Elixir NIF.\n\nThis library is mostly an experiment.\nHowever, it is usable, and all public functions should have tests and documentation,\nso feel free to use it in accordance with the [LICENSE](LICENSE), but caveat emptor.\n\n## motivation/tl;dr\n\nRust has an amazing [regex](https://crates.io/crates/regex) library.\nI wanted to see how it compares to Elixir/Erlang's existing `Regex`/`re` library.\n\nThough more investigation and benchmarking is needed, my takeaways so far:\n\n- Rust is faster for most things, sometimes significantly, sometimes not\n- Rust is consistently _much_ faster (10x, 20x, or more) when the regex does not match the haystack\n- The variance between the median time and the 99%ile time is tighter with Rust\n\nSo, if a general speed increase, a consistent major speedup when the match is not found,\nor 99%ile worst-case latencies matter to you, you may want to check out this library.\nOtherwise, you should probably stick with the builtin `Regex`/`re` libraries,\nas they are very good in their own right.\n\n## Installation\n\n```elixir\ndef deps do\n  [\n    {:regex_rs, git: \"https://github.com/ckampfe/regex_rs.git\"}\n  ]\nend\n```\n\nYou will also need to have an existing Rust/Cargo installation,\nwhich you can get [here.](https://www.rust-lang.org/tools/install)\n\n## Todo\n\n- [ ] Two separate modules: one for regular schedulers one for dirty schedulers\n- [ ] Better tests\n- [ ] More Rust regex API coverage\n- [ ] Does it make sense to try to match Elixir API?\n- [ ] Hex?\n- [ ] Clean up test duplication\n- [x] Examples\n\n## Benchmarks\n\n```\nclark@doomguy:~/code/personal/regex_rs$ MIX_ENV=bench mix run bench.exs\nCompiling NIF crate :regexrust (native/regexrust)...\n    Finished release [optimized] target(s) in 0.00s\nOperating System: Linux\nCPU Information: AMD Ryzen 7 5800X 8-Core Processor\nNumber of Available Cores: 16\nAvailable memory: 50.17 GB\nElixir 1.11.2\nErlang 23.2\n\nBenchmark suite executing with the following configuration:\nwarmup: 2 s\ntime: 5 s\nmemory time: 0 ns\nparallel: 1\ninputs: big hit, big miss, small hit, small miss\nEstimated total run time: 7.93 min\n\nBenchmarking elixir match?/2 with input big hit...\nBenchmarking elixir match?/2 with input big miss...\nBenchmarking elixir match?/2 with input small hit...\nBenchmarking elixir match?/2 with input small miss...\nBenchmarking elixir named_captures/2 with input big hit...\nBenchmarking elixir named_captures/2 with input big miss...\nBenchmarking elixir named_captures/2 with input small hit...\nBenchmarking elixir named_captures/2 with input small miss...\nBenchmarking elixir replace/4 all with input big hit...\nBenchmarking elixir replace/4 all with input big miss...\nBenchmarking elixir replace/4 all with input small hit...\nBenchmarking elixir replace/4 all with input small miss...\nBenchmarking elixir replace/4 first match with input big hit...\nBenchmarking elixir replace/4 first match with input big miss...\nBenchmarking elixir replace/4 first match with input small hit...\nBenchmarking elixir replace/4 first match with input small miss...\nBenchmarking elixir run/2 with input big hit...\nBenchmarking elixir run/2 with input big miss...\nBenchmarking elixir run/2 with input small hit...\nBenchmarking elixir run/2 with input small miss...\nBenchmarking elixir scan/2 with input big hit...\nBenchmarking elixir scan/2 with input big miss...\nBenchmarking elixir scan/2 with input small hit...\nBenchmarking elixir scan/2 with input small miss...\nBenchmarking rust captures/2 with input big hit...\nBenchmarking rust captures/2 with input big miss...\nBenchmarking rust captures/2 with input small hit...\nBenchmarking rust captures/2 with input small miss...\nBenchmarking rust captures_iter/2 with input big hit...\nBenchmarking rust captures_iter/2 with input big miss...\nBenchmarking rust captures_iter/2 with input small hit...\nBenchmarking rust captures_iter/2 with input small miss...\nBenchmarking rust captures_iter_named/2 with input big hit...\nBenchmarking rust captures_iter_named/2 with input big miss...\nBenchmarking rust captures_iter_named/2 with input small hit...\nBenchmarking rust captures_iter_named/2 with input small miss...\nBenchmarking rust captures_named/2 with input big hit...\nBenchmarking rust captures_named/2 with input big miss...\nBenchmarking rust captures_named/2 with input small hit...\nBenchmarking rust captures_named/2 with input small miss...\nBenchmarking rust find/2 with input big hit...\nBenchmarking rust find/2 with input big miss...\nBenchmarking rust find/2 with input small hit...\nBenchmarking rust find/2 with input small miss...\nBenchmarking rust find_iter/2 with input big hit...\nBenchmarking rust find_iter/2 with input big miss...\nBenchmarking rust find_iter/2 with input small hit...\nBenchmarking rust find_iter/2 with input small miss...\nBenchmarking rust is_match/2 with input big hit...\nBenchmarking rust is_match/2 with input big miss...\nBenchmarking rust is_match/2 with input small hit...\nBenchmarking rust is_match/2 with input small miss...\nBenchmarking rust replace/3 named with input big hit...\nBenchmarking rust replace/3 named with input big miss...\nBenchmarking rust replace/3 named with input small hit...\nBenchmarking rust replace/3 named with input small miss...\nBenchmarking rust replace/3 numbered with input big hit...\nBenchmarking rust replace/3 numbered with input big miss...\nBenchmarking rust replace/3 numbered with input small hit...\nBenchmarking rust replace/3 numbered with input small miss...\nBenchmarking rust replace_all/3 named with input big hit...\nBenchmarking rust replace_all/3 named with input big miss...\nBenchmarking rust replace_all/3 named with input small hit...\nBenchmarking rust replace_all/3 named with input small miss...\nBenchmarking rust replace_all/3 numbered with input big hit...\nBenchmarking rust replace_all/3 numbered with input big miss...\nBenchmarking rust replace_all/3 numbered with input small hit...\nBenchmarking rust replace_all/3 numbered with input small miss...\n\n##### With input big hit #####\nName                                   ips        average  deviation         median         99th %\nrust is_match/2                  3029.36 K        0.33 μs  ±1322.81%        0.30 μs        0.40 μs\nrust find/2                      2092.51 K        0.48 μs  ±3436.67%        0.40 μs        0.70 μs\nrust captures/2                  1038.90 K        0.96 μs  ±1545.23%        0.90 μs        1.20 μs\nrust captures_named/2            1023.27 K        0.98 μs  ±1795.82%        0.90 μs        1.20 μs\nelixir match?/2                   985.92 K        1.01 μs  ±1466.44%        0.90 μs        1.70 μs\nelixir run/2                      863.43 K        1.16 μs  ±1271.26%           1 μs        2.20 μs\nelixir named_captures/2           612.18 K        1.63 μs   ±804.69%        1.50 μs        2.80 μs\nrust replace/3 numbered           482.76 K        2.07 μs   ±854.31%        1.90 μs        3.50 μs\nelixir replace/4 first match      466.04 K        2.15 μs   ±534.89%        1.90 μs        5.40 μs\nrust replace/3 named              464.20 K        2.15 μs   ±913.21%           2 μs        3.70 μs\nrust find_iter/2                    4.29 K      232.84 μs    ±32.00%         173 μs      371.20 μs\nrust replace_all/3 numbered         1.13 K      883.65 μs     ±1.48%      882.10 μs      905.55 μs\nrust replace_all/3 named            1.02 K      978.53 μs     ±2.36%      976.10 μs     1003.70 μs\nrust captures_iter/2                0.85 K     1174.95 μs    ±22.47%     1148.80 μs     1616.30 μs\nrust captures_iter_named/2          0.83 K     1209.08 μs    ±12.37%     1241.20 μs     1518.63 μs\nelixir scan/2                       0.51 K     1967.05 μs     ±1.63%     1960.10 μs     2053.59 μs\nelixir replace/4 all                0.41 K     2454.99 μs     ±1.80%     2439.25 μs     2626.15 μs\n\nComparison:\nrust is_match/2                  3029.36 K\nrust find/2                      2092.51 K - 1.45x slower +0.148 μs\nrust captures/2                  1038.90 K - 2.92x slower +0.63 μs\nrust captures_named/2            1023.27 K - 2.96x slower +0.65 μs\nelixir match?/2                   985.92 K - 3.07x slower +0.68 μs\nelixir run/2                      863.43 K - 3.51x slower +0.83 μs\nelixir named_captures/2           612.18 K - 4.95x slower +1.30 μs\nrust replace/3 numbered           482.76 K - 6.28x slower +1.74 μs\nelixir replace/4 first match      466.04 K - 6.50x slower +1.82 μs\nrust replace/3 named              464.20 K - 6.53x slower +1.82 μs\nrust find_iter/2                    4.29 K - 705.36x slower +232.51 μs\nrust replace_all/3 numbered         1.13 K - 2676.89x slower +883.32 μs\nrust replace_all/3 named            1.02 K - 2964.31x slower +978.20 μs\nrust captures_iter/2                0.85 K - 3559.34x slower +1174.62 μs\nrust captures_iter_named/2          0.83 K - 3662.73x slower +1208.75 μs\nelixir scan/2                       0.51 K - 5958.90x slower +1966.72 μs\nelixir replace/4 all                0.41 K - 7437.04x slower +2454.66 μs\n\n##### With input big miss #####\nName                                   ips        average  deviation         median         99th %\nrust is_match/2                    51.07 K       19.58 μs     ±4.52%       19.40 μs          23 μs\nrust find/2                        50.86 K       19.66 μs   ±193.47%       19.40 μs       23.10 μs\nrust find_iter/2                   50.48 K       19.81 μs     ±5.73%       19.80 μs       23.70 μs\nrust replace_all/3 numbered        49.36 K       20.26 μs    ±20.40%       19.80 μs       24.90 μs\nrust captures_named/2              49.08 K       20.37 μs     ±4.77%       20.20 μs          24 μs\nrust captures_iter/2               48.84 K       20.48 μs     ±4.90%       20.20 μs       24.10 μs\nrust captures/2                    48.81 K       20.49 μs     ±5.66%       20.20 μs       24.10 μs\nrust captures_iter_named/2         48.69 K       20.54 μs     ±5.12%       20.20 μs       24.30 μs\nrust replace_all/3 named           48.05 K       20.81 μs    ±17.79%       20.60 μs       25.10 μs\nrust replace/3 numbered            47.81 K       20.92 μs    ±12.55%       20.50 μs          25 μs\nrust replace/3 named               47.69 K       20.97 μs    ±83.39%       20.60 μs       25.10 μs\nelixir named_captures/2             3.05 K      328.37 μs     ±2.31%      326.60 μs      358.41 μs\nelixir scan/2                       2.03 K      493.10 μs     ±6.71%      514.80 μs         535 μs\nelixir match?/2                     2.02 K      495.10 μs    ±45.25%      513.30 μs      536.66 μs\nelixir run/2                        1.99 K      502.70 μs     ±6.51%      522.10 μs      542.40 μs\nelixir replace/4 all                1.63 K      615.28 μs     ±4.64%      611.50 μs      684.99 μs\nelixir replace/4 first match        1.62 K      618.54 μs     ±4.89%      612.70 μs      689.53 μs\n\nComparison:\nrust is_match/2                    51.07 K\nrust find/2                        50.86 K - 1.00x slower +0.0806 μs\nrust find_iter/2                   50.48 K - 1.01x slower +0.23 μs\nrust replace_all/3 numbered        49.36 K - 1.03x slower +0.68 μs\nrust captures_named/2              49.08 K - 1.04x slower +0.79 μs\nrust captures_iter/2               48.84 K - 1.05x slower +0.90 μs\nrust captures/2                    48.81 K - 1.05x slower +0.91 μs\nrust captures_iter_named/2         48.69 K - 1.05x slower +0.96 μs\nrust replace_all/3 named           48.05 K - 1.06x slower +1.23 μs\nrust replace/3 numbered            47.81 K - 1.07x slower +1.34 μs\nrust replace/3 named               47.69 K - 1.07x slower +1.39 μs\nelixir named_captures/2             3.05 K - 16.77x slower +308.79 μs\nelixir scan/2                       2.03 K - 25.18x slower +473.52 μs\nelixir match?/2                     2.02 K - 25.28x slower +475.52 μs\nelixir run/2                        1.99 K - 25.67x slower +483.12 μs\nelixir replace/4 all                1.63 K - 31.42x slower +595.70 μs\nelixir replace/4 first match        1.62 K - 31.59x slower +598.96 μs\n\n##### With input small hit #####\nName                                   ips        average  deviation         median         99th %\nrust is_match/2                    11.71 M       85.40 ns   ±165.64%         100 ns         100 ns\nrust find/2                         3.82 M      261.90 ns  ±3079.13%         200 ns         600 ns\nrust find_iter/2                    1.93 M      518.53 ns  ±4644.21%         400 ns         800 ns\nrust captures/2                     1.72 M      581.51 ns  ±2957.61%         500 ns         900 ns\nrust captures_named/2               1.60 M      624.63 ns  ±2859.90%         500 ns         900 ns\nrust replace/3 numbered             1.26 M      796.21 ns  ±1359.49%         800 ns        1100 ns\nrust replace/3 named                1.21 M      827.90 ns  ±1317.90%         800 ns        1100 ns\nrust replace_all/3 numbered         1.15 M      871.05 ns  ±1189.45%         800 ns        1200 ns\nrust replace_all/3 named            1.03 M      973.22 ns  ±1115.19%         900 ns        1400 ns\nelixir match?/2                     0.94 M     1061.88 ns  ±1516.91%        1000 ns        1100 ns\nrust captures_iter/2                0.86 M     1164.51 ns  ±1574.91%        1000 ns        1500 ns\nelixir run/2                        0.82 M     1219.55 ns  ±1141.04%        1100 ns        1500 ns\nrust captures_iter_named/2          0.77 M     1293.11 ns  ±1329.19%        1100 ns        1700 ns\nelixir named_captures/2             0.58 M     1727.42 ns   ±771.23%        1600 ns        3100 ns\nelixir replace/4 first match        0.56 M     1799.72 ns   ±628.61%        1600 ns        3700 ns\nelixir scan/2                       0.30 M     3352.83 ns   ±332.05%        3000 ns        9600 ns\nelixir replace/4 all                0.24 M     4181.01 ns   ±261.94%        3800 ns       10200 ns\n\nComparison:\nrust is_match/2                    11.71 M\nrust find/2                         3.82 M - 3.07x slower +176.50 ns\nrust find_iter/2                    1.93 M - 6.07x slower +433.13 ns\nrust captures/2                     1.72 M - 6.81x slower +496.12 ns\nrust captures_named/2               1.60 M - 7.31x slower +539.23 ns\nrust replace/3 numbered             1.26 M - 9.32x slower +710.81 ns\nrust replace/3 named                1.21 M - 9.69x slower +742.51 ns\nrust replace_all/3 numbered         1.15 M - 10.20x slower +785.65 ns\nrust replace_all/3 named            1.03 M - 11.40x slower +887.82 ns\nelixir match?/2                     0.94 M - 12.43x slower +976.48 ns\nrust captures_iter/2                0.86 M - 13.64x slower +1079.11 ns\nelixir run/2                        0.82 M - 14.28x slower +1134.15 ns\nrust captures_iter_named/2          0.77 M - 15.14x slower +1207.71 ns\nelixir named_captures/2             0.58 M - 20.23x slower +1642.02 ns\nelixir replace/4 first match        0.56 M - 21.07x slower +1714.32 ns\nelixir scan/2                       0.30 M - 39.26x slower +3267.43 ns\nelixir replace/4 all                0.24 M - 48.96x slower +4095.61 ns\n\n##### With input small miss #####\nName                                   ips        average  deviation         median         99th %\nrust is_match/2                     9.98 M      100.24 ns   ±204.12%         100 ns         200 ns\nrust find/2                         9.49 M      105.38 ns   ±202.28%         100 ns         200 ns\nrust find_iter/2                    8.08 M      123.69 ns   ±125.38%         100 ns         200 ns\nrust captures_iter/2                7.58 M      132.00 ns   ±136.26%         100 ns         200 ns\nrust captures/2                     7.56 M      132.23 ns   ±119.94%         100 ns         200 ns\nrust captures_iter_named/2          7.52 M      133.06 ns   ±198.45%         100 ns         200 ns\nrust captures_named/2               7.43 M      134.57 ns  ±2807.48%         100 ns         200 ns\nrust replace_all/3 numbered         3.45 M      289.62 ns  ±6127.69%         200 ns         600 ns\nrust replace_all/3 named            3.44 M      290.59 ns  ±6108.16%         200 ns         600 ns\nrust replace/3 named                3.29 M      303.63 ns  ±6162.33%         300 ns         700 ns\nrust replace/3 numbered             3.15 M      317.11 ns  ±6515.47%         300 ns         700 ns\nelixir match?/2                     0.77 M     1291.02 ns   ±756.20%        1300 ns        1400 ns\nelixir run/2                        0.75 M     1332.98 ns   ±981.90%        1300 ns        1400 ns\nelixir scan/2                       0.67 M     1495.97 ns   ±857.84%        1400 ns        1700 ns\nelixir named_captures/2             0.55 M     1816.08 ns   ±782.63%        1700 ns        2900 ns\nelixir replace/4 first match        0.51 M     1955.41 ns   ±723.37%        1800 ns        3400 ns\nelixir replace/4 all                0.46 M     2163.73 ns   ±543.07%        2000 ns        4700 ns\n\nComparison:\nrust is_match/2                     9.98 M\nrust find/2                         9.49 M - 1.05x slower +5.14 ns\nrust find_iter/2                    8.08 M - 1.23x slower +23.46 ns\nrust captures_iter/2                7.58 M - 1.32x slower +31.76 ns\nrust captures/2                     7.56 M - 1.32x slower +31.99 ns\nrust captures_iter_named/2          7.52 M - 1.33x slower +32.82 ns\nrust captures_named/2               7.43 M - 1.34x slower +34.33 ns\nrust replace_all/3 numbered         3.45 M - 2.89x slower +189.38 ns\nrust replace_all/3 named            3.44 M - 2.90x slower +190.35 ns\nrust replace/3 named                3.29 M - 3.03x slower +203.39 ns\nrust replace/3 numbered             3.15 M - 3.16x slower +216.87 ns\nelixir match?/2                     0.77 M - 12.88x slower +1190.78 ns\nelixir run/2                        0.75 M - 13.30x slower +1232.74 ns\nelixir scan/2                       0.67 M - 14.92x slower +1395.74 ns\nelixir named_captures/2             0.55 M - 18.12x slower +1715.84 ns\nelixir replace/4 first match        0.51 M - 19.51x slower +1855.18 ns\nelixir replace/4 all                0.46 M - 21.59x slower +2063.50 ns\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fckampfe%2Fregex_rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fckampfe%2Fregex_rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fckampfe%2Fregex_rs/lists"}