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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Browser:
Chrome 122
Operating system:
Mac OS X 10.15.7
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
Using string comparison
442211.9 Ops/sec
Using regex
388853.7 Ops/sec
Using array includes
451251.9 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);