String starts with: Regex vs .slice

Benchmark created by Bri on


Setup

var PREFIX = '::'; 
    var str = PREFIX + 'hello world';

Test runner

Ready to run.

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

Revisions

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