Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
indexOf vs includes in strings
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser:
Chrome 120
Operating system:
Linux
Device Platform:
Desktop
Date tested:
2 years ago
Test name
Executions per second
includes
1498346.0 Ops/sec
!~indexOf
1499284.0 Ops/sec
indexOf > -1
1505453.2 Ops/sec
indexOf !== -1
1503583.9 Ops/sec
test
1142791.1 Ops/sec
match
1057815.9 Ops/sec
Script Preparation code:
var long = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'; var short = 'file.ext'; var s1 = 'tempor'; var s2 = '.ext'; var re1 = /tempor/; var re2 = /\.ext/;
Tests:
includes
long.includes(s1); long.includes(s2); short.includes(s1); short.includes(s2);
!~indexOf
!~long.indexOf(s1); !~long.indexOf(s2); !~short.indexOf(s1); !~short.indexOf(s2);
indexOf > -1
long.indexOf(s1) > -1; long.indexOf(s2) > -1; short.indexOf(s1) > -1; short.indexOf(s2) > -1;
indexOf !== -1
long.indexOf(s1) !== -1; long.indexOf(s2) !== -1; short.indexOf(s1) !== -1; short.indexOf(s2) !== -1;
test
re1.test(long); re2.test(long); re1.test(short); re2.test(short);
match
long.match(re1) !== null; long.match(re2) !== null; short.match(re1) !== null; short.match(re2) !== null;