Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
test b@b regexp list inverted
(version: 0)
Comparing performance of:
regexp of list vs list of regexps
Created:
2 years ago
by:
Guest
Jump to the latest result
Tests:
regexp of list
new RegExp("(^([^./]+\\.)*slack\\.com/)|(^([^./]+\\.)*microsoft\\.com/)|(^([^./]+\\.)*beamy\\.io/)").test("sub1.sub2.slack.com/");
list of regexps
new RegExp("^([^./]+\\.)*slack\\.com/").test("sub1.sub2.slack.com/"); new RegExp("^([^./]+\\.)*microsoft\\.com/").test("sub1.sub2.slack.com/"); new RegExp("^([^./]+\\.)*beamy\\.io/").test("sub1.sub2.slack.com/");
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
regexp of list
list of regexps
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
Browser/OS:
Chrome 121 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
regexp of list
3621568.0 Ops/sec
list of regexps
2036345.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'd be happy to explain the benchmark being tested on MeasureThat.net. **What is tested?** The benchmark tests the performance of different approaches for regular expression (RegExp) matching in JavaScript. The test cases involve creating and executing multiple Regexps with varying patterns against a fixed input string ("sub1.sub2.slack.com/"). **Options compared:** There are two main options being compared: 1. **Single RegExp**: This approach creates a single RegExp object with multiple patterns separated by pipes (`|`). The `test()` method is called for each pattern, and the resulting matches are not collected. 2. **List of Regexps**: This approach creates multiple separate RegExp objects, one for each pattern in the list. Each `test()` method call is executed individually. **Pros and Cons:** 1. **Single RegExp**: * Pros: + Reduced memory allocation and garbage collection overhead since only a single object needs to be created. + Potential for faster execution if the patterns are closely related (e.g., shared prefix or suffix). * Cons: + Increased complexity due to multiple pattern testing in a single `test()` call. + May lead to slower performance if the patterns are not optimized or if there are many patterns. 2. **List of Regexps**: * Pros: + Simplified code and easier maintenance, as each RegExp is separate and distinct. + Easier to optimize individual patterns for better performance. * Cons: + Higher memory allocation and garbage collection overhead since multiple objects need to be created. + Slower execution due to the overhead of creating and disposing RegExp objects. **Library usage:** There is no explicit library usage in these test cases. However, it's likely that the JavaScript engine being tested (e.g., V8) provides its own implementation of Regexps, which might include internal optimizations or complexities not visible in this benchmark. **Special JS features or syntax:** There are no special JS features or syntax used in these test cases. The focus is on the RegExp matching performance and optimization. **Alternative approaches:** Other alternatives for regular expression matching in JavaScript include: 1. **Using a string replacement library**: Instead of creating Regexps, libraries like String.prototype.replace() can be used to perform string replacements. 2. **Regular expression caching**: Some JavaScript engines provide caching mechanisms for frequently used Regexps, which can improve performance. 3. **Just-In-Time (JIT) compilation**: Some JavaScript engines use JIT compilation to optimize RegExp execution at runtime. Keep in mind that these alternatives might not directly address the specific question of optimal RegExp matching approach but rather offer additional optimization techniques or alternatives for string manipulation tasks.
Related benchmarks:
regexp n such
regex vs length
Case insensitive string comparison 2
111 regex test
new RegExp test
Comments
Confirm delete:
Do you really want to delete benchmark?