{"id":16419698,"url":"https://github.com/salaah01/regex-benchmark","last_synced_at":"2025-03-21T03:32:51.929Z","repository":{"id":215872899,"uuid":"739874331","full_name":"Salaah01/regex-benchmark","owner":"Salaah01","description":"A Rust binary to benchmark regex expressions","archived":false,"fork":false,"pushed_at":"2024-08-12T16:55:06.000Z","size":806,"stargazers_count":2,"open_issues_count":8,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-12T07:25:35.641Z","etag":null,"topics":["benchmark","benchmarking","performance","performance-testing","regex","regex-pattern","regexp","rust","rust-lang"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Salaah01.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2024-01-06T20:04:38.000Z","updated_at":"2024-10-09T14:46:09.000Z","dependencies_parsed_at":"2024-05-15T15:27:11.288Z","dependency_job_id":"c3418a63-6d36-41da-9369-36da22a62b5a","html_url":"https://github.com/Salaah01/regex-benchmark","commit_stats":{"total_commits":25,"total_committers":3,"mean_commits":8.333333333333334,"dds":"0.16000000000000003","last_synced_commit":"94cc2a359b00b2e542e3e75d4b72e8585e3e3691"},"previous_names":["salaah01/regex-speed","salaah01/regex-benchmark"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salaah01%2Fregex-benchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salaah01%2Fregex-benchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salaah01%2Fregex-benchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Salaah01%2Fregex-benchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Salaah01","download_url":"https://codeload.github.com/Salaah01/regex-benchmark/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221811374,"owners_count":16884305,"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":["benchmark","benchmarking","performance","performance-testing","regex","regex-pattern","regexp","rust","rust-lang"],"created_at":"2024-10-11T07:25:37.687Z","updated_at":"2024-10-28T09:16:31.520Z","avatar_url":"https://github.com/Salaah01.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Regex Benchmark: Performance Visualization Tool for Regular Expressions\n\n\n- [Regex Benchmark: Performance Visualization Tool for Regular Expressions](#regex-benchmark-performance-visualization-tool-for-regular-expressions)\n  - [Description](#description)\n  - [Why Regex Performance Matters?](#why-regex-performance-matters)\n  - [Examples](#examples)\n  - [Installation](#installation)\n    - [Linux](#linux)\n    - [Windows](#windows)\n  - [Usage](#usage)\n  - [Contributing](#contributing)\n\n\n## Description\n\nRegex Benchmark is a utility tool aimed at demystifying the performance of regular expressions. It provides a visual representation of how different regex patterns perform, especially useful when dealing with complex expressions where performance implications are not immediately apparent.\n\n## Why Regex Performance Matters?\n\nUnderstanding the performance of regular expressions is crucial for several reasons:\n\n* **Security** - Avoding [ReDoS attack](https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS) attacks.\n* **Performance** - Ensuring efficient execution, crucial for user experience and server load management.\n* **Cost** - Minimising computational resources, especially in cloud-based solutions.\n* **Real-World Lessons** - Learning from incidents like [Cloudflare's global outage](https://blog.cloudflare.com/details-of-the-cloudflare-outage-on-july-2-2019/).\n\n\n## Examples\n\nLet's suppose I want to test the performance of the following three request expressions:\n\n1. `=`\n2. `.*(=).*`\n3. `.?(=).*`\n\nAll of these expressions are valid, and they all do the same thing. In this example, it's easy to see that the first expression is the most efficient. However, in more complex expressions, it's not always easy to see which expression is the most efficient. This is where `regex-benchmark` comes in.\n\nWe'll run test each of the regex expressions using the following options:\n\n* `--max-length 100000` - The max string length to test will be 100,000.\n* `--step-size 10` - The step size will be 10, meaning the string length will increase by 10 each iteration.\n* `--num-tests 5` - We will run each test 5 times plotting each result onto the graph.\n* `--required-str x=xxxxxxxxxxxxxx` - The random strings that are generated will have the string `x=xxxxxxxxxxxxxx` somewhere in them.\n* `--method find` - We want to locate the \"=\" in the string. This isn't at all useful in a real life example, but it's a nice way to demonstrate the performance of the regex expressions.\n\nLet's run the tests:\n\n```bash\nregex-benchmark \\\n  --regex '=' \\\n  --max-length 100000 \\\n  --step-size 10 \\\n  --num-tests 5 \\\n  --required-str x=xxxxxxxxxxxxxx \\\n  --method find\n```\n\n![Example 1 results](./docs/examples/img/example-test-1.png)\n\n```bash\nregex-benchmark \\\n  --regex '.*(=).*' \\\n  --max-length 100000 \\\n  --step-size 10 \\\n  --num-tests 5 \\\n  --required-str x=xxxxxxxxxxxxxx \\\n  --method find\n```\n\n![Example 2 results](./docs/examples/img/example-test-2.png)\n\n```bash\nregex-benchmark \\\n  --regex '.?(=).*' \\\n  --max-length 100000 \\\n  --step-size 10 \\\n  --num-tests 5 \\\n  --required-str x=xxxxxxxxxxxxxx \\\n  --method find\n```\n\n![Example 3 results](./docs/examples/img/example-test-3.png)\n\nAlthough all three expressions are valid and we can retrieve the \"=\" from the results, we can see that the performance of each expression is very different.\n\nThe first expression is the most efficient. Although we do have a couple of outliers, the performance is very consistent giving us a good indication that the result is constant time.\n\nThe second expression is the least efficient. We can see a linear growth with a increase in spread as the input size increases. **This might look like a time complexity of O(n), however this isn't actually true. The time complexity is actually O(n^3) in terms of how many steps actually need to be executed. This graph instead represents the actual time to perform the regex search**.\n\nThe final expression is the most interesting. We can see that it is slower than the first expression, but faster than the second. The biggest difference is that the spread is absolutely massive!\n\n\n## Installation\n\n### Linux\n\n1. Download the latest `regex-benchmark` binary from [releases page](https://github.com/Salaah01/regex-benchmark/releases).\n2. Ubuntu users will need to install additional dependencies:\n    ```bash\n    sudo apt install pkg-config libfreetype6-dev libfontconfig1-dev\n    ```\n3. Run the binary in the terminal with the `--help` flag to see the available options:\n    ```bash\n    ./regex-benchmark --help\n    ```\n\n### Windows\n\n1. Download the latest `regex-benchmark.exe` binary from [releases page](https://github.com/Salaah01/regex-benchmark/releases).\n2. Run the binary in Powershell/CMD with the `--help` flag to see the available options:\n    ```powershell\n    .\\regex-benchmark.exe --help\n    ```\n\n## Usage\n\nOne you have installed the binary, you can run it with the `--help` flag to see the available options:\n\n```bash\n./regex-benchmark --help\n```\n\nFor a quick start, you can try running one of the regex expressions from the [examples](#examples) above:\n\n```bash\nregex-benchmark \\\n  --regex '.?(=).*' \\\n  --max-length 100000 \\\n  --step-size 10 \\\n  --num-tests 5 \\\n  --required-str x=xxxxxxxxxxxxxx \\\n  --method find\n```\n\n## Contributing\n\nContributions are welcome! Whether it's reporting bugs, suggesting features, or submitting code changes, please refer to our [contributing guide](./CONTRIBUTING.md). We appreciate contributions from developers of all skill levels.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalaah01%2Fregex-benchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsalaah01%2Fregex-benchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsalaah01%2Fregex-benchmark/lists"}