String starts with: startsWith vs .slice (v4)

Revision 4 of this benchmark created on


Setup

var PREFIX = '::'; 
var str = () => `${PREFIX}${Math.random()}`;

Test runner

Ready to run.

Testing in
TestOps/sec
Startswith
str().startsWith(PREFIX)
ready
.slice()
str().slice(0, PREFIX.length) === PREFIX;
ready
RegExp
new RegExp('^' + PREFIX).test(str());
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.