Regex Test vs Includes

JavaScript performance comparison

Test case created by Callum Denby

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const urls = [
    'http://website.com/my-account/test',
    'https://website.com/my-account',
    'https://website.com/not/valid/',
    'http://website.com/not/valid/at/all'
  ];

};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Regex
for(const url of urls) {
  /\/my-account/.test(url);
}
pending…
Includes
for(const url of urls) {
  url.includes('/my-account');
}
pending…
IndexOf
for(const url of urls) {
  url.indexOf('/my-account') !== -1;
}
pending…

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

0 Comments