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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0
Browser:
Chrome 125
Operating system:
Windows
Device Platform:
Desktop
Date tested:
one year ago
Test name
Executions per second
Using string comparison
242263.0 Ops/sec
Using regex
193970.9 Ops/sec
Using array includes
220111.7 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);