Regexp vs includes

Benchmark created by Anthony Ricaud on


Setup

const pattern = /[?&]utm_/;
  const needle = 'utm_';
  const matching_url = 'http://foo.com/?bar=baz&utm_source=12';
  const non_matching_url = 'http://foo.com/?bar=baz&atm_source=12';

Test runner

Ready to run.

Testing in
TestOps/sec
Mtching Regexp
pattern.test(matching_url);
ready
Matching includes
matching_url.includes(needle);
ready
Non Matching Regexp
pattern.test(non_matching_url);
ready
Non Matching indexOf
non_matching_url.indexOf(needle) !== -1;
ready
Non Matching indexOf
matching_url.indexOf(needle) !== -1;
ready
Non Matching includes
non_matching_url.includes(needle);
ready

Revisions

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

  • Revision 1: published by Anthony Ricaud on