Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
RegExp constructor vs literal vs premade, constructing in function, inline the test
Testing performance when using a new RegExp object vs a literal regex
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser:
Chrome 123
Operating system:
Windows
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
new RegExp()
5547883.5 Ops/sec
RegExp() factory
5522947.0 Ops/sec
Literal
13249286.0 Ops/sec
Literal premade
9706220.0 Ops/sec
Script Preparation code:
function getReConstructor() { return new RegExp('^[0-9a-fA-F]{24}$').test('132abc67219f019afe12901a'); } function getReFactory() { return RegExp('^[0-9a-fA-F]{24}$').test('132abc67219f019afe12901a'); } function getReLiteral() { return /^[0-9a-fA-F]{24}$/.test('132abc67219f019afe12901a'); } var premadeLiteral = /^[0-9a-fA-F]{24}$/; function getRePremadeLiteral() { return premadeLiteral.test('132abc67219f019afe12901a'); }
Tests:
new RegExp()
getReConstructor()
RegExp() factory
getReFactory()
Literal
getReLiteral()
Literal premade
getRePremadeLiteral()