Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
new RegExp mem test
(version: 0)
Comparing performance of:
literal vs RegExp vs Constructor
Created:
5 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var reConstructor = new RegExp('^[0-9a-fA-F]{24}$') var reSimpleConstructor = RegExp('^[0-9a-fA-F]{24}$') var reLiteral = /^[0-9a-fA-F]{24}$/
Tests:
literal
reLiteral.test('132abc67219f019afe12901a')
RegExp
reSimpleConstructor.test('132abc67219f019afe12901a')
Constructor
reConstructor.test('132abc67219f019afe12901a')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
literal
RegExp
Constructor
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):
Let's break down the provided benchmark and its test cases. **Benchmark Definition JSON** The provided JSON defines a JavaScript microbenchmark that tests different approaches to creating regular expressions in JavaScript. The three options being compared are: 1. **Literal**: A literal string is used directly in the regex pattern. 2. **Simple RegExp**: A new `RegExp` object is created using the `RegExp` constructor, passing the same string as its argument. 3. **Constructor**: Another approach is to create a regular expression constructor function and then call it with the desired pattern. The script preparation code defines these three constructors: * `reLiteral`: A literal string used directly in the regex pattern. * `reSimpleConstructor`: A simple `RegExp` object created using the `RegExp` constructor. * `reConstructor`: A custom regular expression constructor function. **Pros and Cons of each approach** 1. **Literal**: This approach is likely to be the fastest since it avoids creating a new RegExp object. However, it may not provide a clear advantage over other approaches if the regex pattern is complex or requires optimization. 2. **Simple RegExp**: Creating a simple `RegExp` object using the constructor can provide some benefits, such as avoiding unnecessary memory allocations and improving cache locality. However, this approach still involves creating a new object, which might incur some overhead. 3. **Constructor**: The custom constructor function approach may provide the most control over optimization and caching. However, it introduces an additional layer of complexity and potential performance overhead due to the creation of a new function. **Other considerations** The benchmark also includes two test cases: * `reLiteral.test('132abc67219f019afe12901a')`: Tests the literal approach with a specific input string. * `reSimpleConstructor.test('132abc67219f019afe12901a')` and `reConstructor.test('132abc67219f019afe12901a')`: Test the simple RegExp and custom constructor approaches, respectively. **JavaScript features used** The benchmark uses JavaScript's regular expression syntax and object creation mechanisms to create and test the different constructors. Specifically, it utilizes: * The `RegExp` constructor to create new regular expression objects. * The `test()` method on a regular expression object to evaluate strings against it. * Custom function creation using the `function` keyword. **Library usage** There are no external libraries used in this benchmark. **Special JavaScript features and syntax** The custom constructor approach uses a feature of JavaScript called "arrow functions" (introduced in ECMAScript 2015) to define the regular expression constructor function.
Related benchmarks:
RegExp constructor vs literal vs RegExp+Literal
Regex JS testing
RegExp constructor vs literal (re-do creation)
Test RegExp Performance
Comments
Confirm delete:
Do you really want to delete benchmark?