regex vs two indexOf

JavaScript performance comparison

Test case created by Mamanze

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  const url = '/community/foo/1234_plid';

};
</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
/^\/community\/.*\_plid/.test(url)
pending…
two indexOf
url.indexOf('/community/') === 0 && url.indexOf('_plid') === (url.length - 5)
pending…
substrings
url.substring(0, 11) === '/community/' && url.substring(url.length - 5, url.length) === '_plid'
pending…
withs
url.startsWith('/community/') && url.endsWith('_plid')
pending…
substr
url.substr(0, 11) === '/community/' && url.substr(url.length - 5, 5) === '_plid'
pending…
lastindexof
url.indexOf('/community/') === 0 && url.lastIndexOf('_plid') === (url.length - 5)
pending…

Compare results of other browsers

Revisions

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

0 Comments