Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
regex 0001 + 2
(version: 0)
Comparing performance of:
REGEX_1 vs REGEX_2 vs REGEX_3
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var REGEX_1 = /"{0,1}cpf"{0,1}[:=]"{0,1}([\w\s]{1,})/; var REGEX_2 = /"{0,1}cpf"{0,1}[:=]\"{0,1}([\w\s]+)/; var REGEX_3 = /"{0,1}cpf"{0,1}[:=]"{0,1}([^ ,]*)/;
Tests:
REGEX_1
REGEX_1.test("cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12")
REGEX_2
REGEX_2.test("cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12")
REGEX_3
REGEX_2.test("cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12,cpf=12")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
REGEX_1
REGEX_2
REGEX_3
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Explanation** The provided benchmark is designed to test the performance of regular expression (regex) patterns in JavaScript. The goal is to compare the execution speed of three different regex patterns: `REGEX_1`, `REGEX_2`, and `REGEX_3`. **Regex Patterns** 1. **`REGEX_1`:** ```javascript var REGEX_1 = /"{0,1}cpf"{0,1}[=:]"{0,1}([\\w\\s]{1,})/; ``` This regex pattern matches the string "cpf" with optional surrounding quotes and an optional colon and equals sign (`[:=]`). The parentheses around `[^ ,]*` capture one or more word characters (letters, numbers, or underscores) after the colon. 2. **`REGEX_2`:** ```javascript var REGEX_2 = /"{0,1}cpf"{0,1}[=:]\\\"{0,1}([\\w\\s]+)/; ``` This regex pattern is similar to `REGEX_1`, but with a backslash (`\`) before the colon and equals sign (`[:=]`), indicating that they are escaped characters. 3. **`REGEX_3`:** ```javascript var REGEX_3 = /"{0,1}cpf"{0,1}[=:]"{0,1}([^ ,]*)/; ``` This regex pattern is similar to `REGEX_1`, but with a different capture group for the character class `[^ ,]*`. This captures any single character that is not whitespace (`[^` represents "not", and ` ` represents whitespace). **Library: None** There are no libraries used in this benchmark. **Special JS Feature/Syntax: None** There are no special JavaScript features or syntaxes used in this benchmark. **Pros and Cons of Each Approach** 1. **`REGEX_1`:** * Pros: + Easy to read and understand + Fast execution speed * Cons: + May not match all possible inputs (e.g., `cpf=12` without quotes) 2. **`REGEX_2`:** * Pros: + Matches the string "cpf" with optional surrounding quotes and an optional colon and equals sign (`[:=]`) + Fast execution speed * Cons: + May not be as readable as `REGEX_1` 3. **`REGEX_3`:** * Pros: + Matches the string "cpf" with an optional colon and equals sign (`[:=]`) + Captures any single character that is not whitespace (`[^ ,]*`) * Cons: + May be less readable than `REGEX_1` or `REGEX_2` **Other Alternatives** If you need to test regex patterns in JavaScript, other alternatives include: * Using a library like [regex-tester](https://regex-tester.com/) or [regexr](https://regexr.com/) * Using a testing framework like Jest or Mocha * Writing unit tests for your code using a testing framework Keep in mind that the choice of alternative depends on your specific use case and requirements.
Related benchmarks:
regex 0001
regex 0001 + 1
regex 0001 + 4
regex 0001 + 5
Comments
Confirm delete:
Do you really want to delete benchmark?