Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
regex 0001 + 1
(version: 0)
Comparing performance of:
REGEX_1 vs REGEX_2
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]+)/;
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")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
REGEX_1
REGEX_2
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.1:latest
, generated one year ago):
Let's break down what's being tested and compared in this benchmark. **Overview** The benchmark is testing the performance of two regular expressions, `REGEX_1` and `REGEX_2`, which are used to match strings containing CPF numbers (a type of Brazilian identification number). The test cases involve running these regular expressions on a large string with multiple CPF numbers. **Regular Expressions** Both `REGEX_1` and `REGEX_2` are using the same pattern, but with some differences in how they're written: ```javascript 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]+)/; ``` The main difference is in the way they're escaping double quotes (`"`). In `REGEX_1`, the backslash (`\`) is used to escape a single quote (because it's inside a string), whereas in `REGEX_2`, the forward slash (`/`) is used as an escape character, and then another backslash is used to escape the double quote. **Test Cases** The benchmark has two test cases: 1. **`REGEX_1`**: This test case uses the regular expression `REGEX_1` and runs it on a string containing 12 CPF numbers. 2. **`REGEX_2`**: This test case uses the regular expression `REGEX_2` and runs it on the same string as above. **Benchmark Results** The benchmark results show the execution per second (EPS) for each test case: * `REGEX_1`: 10,770,930 EPS * `REGEX_2`: 5,535,222.5 EPS This suggests that `REGEX_1` is about twice as fast as `REGEX_2`. **Library/Feature** No external libraries are used in this benchmark. **Alternatives** If you need to match CPF numbers in JavaScript, you can use a simpler approach without regular expressions: ```javascript function matchCpf(cpf) { const cpfRegex = /^([0-9]{3}\.){2}[0-9]{3}-[0-9]{2}$/; return cpfRegex.test(cpf); } ``` This function uses a string pattern to match CPF numbers, which might be more efficient and easier to understand than regular expressions. Keep in mind that the performance difference between `REGEX_1` and `REGEX_2` is relatively small, and you should consider other factors like readability and maintainability when choosing an approach.
Related benchmarks:
regex 0001
regex 0001 + 2
regex 0001 + 4
regex 0001 + 5
Comments
Confirm delete:
Do you really want to delete benchmark?