Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
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
Test name
Executions per second
Using string comparison
1147695.1 Ops/sec
Using regex
1019981.1 Ops/sec
Using array includes
1115549.6 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);