Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Regex tests Dani
(version: 0)
Comparing performance of:
new RegExp() vs Literal notation
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var reConstructor = new RegExp('^(([^<>()\\[\\]\\.,;:\\s@"]+(\\.[^<>()\\[\\]\\.,;:\\s@"]+)*)|(".+"))@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}])|(([a-zA-Z0-9\\-]+\\.)+[a-zA-Z]{2,}))$'); var reLiteral = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,}))$/;
Tests:
new RegExp()
reConstructor.test('danimrthotmail.com')
Literal notation
reLiteral.test('danimrthotmail.com')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
new RegExp()
Literal notation
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Browser/OS:
Chrome 128 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
new RegExp()
2798422.5 Ops/sec
Literal notation
2819462.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Overview** The provided JSON represents a benchmark test case for JavaScript regex patterns using the MeasureThat.net platform. The goal is to compare the performance of two approaches: creating a new RegExp object with literal notation (`reLiteral`) versus creating one with constructor syntax (`new RegExp()`). **Benchmark Definition** The benchmark definition consists of two parts: 1. **Script Preparation Code**: This section defines a RegExp constructor and a literal RegExp expression, `reConstructor` and `reLiteral`, respectively. 2. **Html Preparation Code**: This section is empty. **Individual Test Cases** There are two individual test cases: 1. **new RegExp()**: Tests the performance of creating a new RegExp object with the constructor syntax. * Benchmark Definition: `reConstructor.test('danimrthotmail.com')` 2. **Literal notation**: Tests the performance of using literal notation to define the RegExp pattern. * Benchmark Definition: `reLiteral.test('danimrthotmail.com')` **Performance Comparison** The two approaches differ in how they define the RegExp pattern: 1. **Constructor Syntax (`new RegExp()`)**: * Pros: + Can be used to define more complex patterns with multiple groups and options. + Allows for dynamic pattern definition using variables or functions. * Cons: + Can lead to slower performance due to the overhead of creating a new object and parsing the pattern string. 2. **Literal Notation (`reLiteral`)**: * Pros: + Faster performance since it doesn't involve object creation and parsing. + More concise and readable syntax for simple patterns. * Cons: + Limited to defining simple patterns with only one group. **Library** There is no specific library used in this benchmark. The RegExp constructor and literal notation are built-in JavaScript features. **JavaScript Feature** There is no special JavaScript feature or syntax mentioned in the provided JSON. **Other Alternatives** If you need to test other approaches for creating or defining RegExp patterns, consider: 1. **RegExp.prototype.test()**: A more concise way to define and test RegExp patterns. 2. **Regex engine APIs**: Some browsers have built-in regex engines that provide additional features and performance benefits. Keep in mind that the choice of approach depends on your specific use case and requirements. MeasureThat.net provides a convenient platform for comparing different JavaScript implementation details.
Related benchmarks:
path regex bis
QuoteTest
RegEx.test2 vs. String.includes vs. String.match
RegEx.exec vs String.test
Comments
Confirm delete:
Do you really want to delete benchmark?