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,}))$/;
reConstructor.test('danimrthotmail.com')
reLiteral.test('danimrthotmail.com')
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
new RegExp() | |
Literal notation |
Test name | Executions per second |
---|---|
new RegExp() | 2798422.5 Ops/sec |
Literal notation | 2819462.5 Ops/sec |
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:
reConstructor
and reLiteral
, respectively.Individual Test Cases
There are two individual test cases:
reConstructor.test('danimrthotmail.com')
reLiteral.test('danimrthotmail.com')
Performance Comparison
The two approaches differ in how they define the RegExp pattern:
new RegExp()
):reLiteral
):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:
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.