Toggle navigation
MeasureThat
.net
Create a benchmark
Tools
Feedback
Feature Requests
FAQ
Register
Log In
Run results for:
Regex vs String comparison
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 18_1_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1.1 Mobile/15E148 Safari/604.1
Browser:
Mobile Safari 18
Operating system:
iOS 18.1.1
Device Platform:
Mobile
Date tested:
one year ago
Benchmark engine:
Benchmark.js
Using string comparison
1.1M/s
Using array includes
1.1M/s
Using regex
1.0M/s
View exact numbers
Test name
Executions per second
✓
Using string comparison
1,147,695 Ops/sec
Using array includes
1,115,550 Ops/sec
Using regex
1,019,981 Ops/sec
Tests:
Using string comparison
const contentType = 'application/json'; const match = contentType === 'application/json' || contentType === 'application/json; charset=utf-8'; console.log(match);
Using regex
const RE_CONTENT_TYPE_JSON = new RegExp('^application/json(; charset=utf-8)?$', 'i'); const contentType = 'application/json'; const match = RE_CONTENT_TYPE_JSON.test(contentType); console.log(match);
Using array includes
const contentType = 'application/json'; const match = ['application/json', 'application/json; charset=utf-8'].includes(contentType); console.log(match);