RegExp test / search / match vs. indexOf

JavaScript performance comparison

Revision 98 of this test case created by

Preparation code

<script>
  var str = 'https://crm.zoho.com/crm/ShowHomePage.do?module=CustomModule1';
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var precompiledRegex1 = /(http|https):\/\/.+\.(facebook|youtube|yahoo|detik|liputan6|kaskus|tokopedia|bukalapak)/;
  var precompiledRegex2 = /(http|https):\/\/.+\.(facebook|youtube|yahoo|detik|liputan6|kaskus|tokopedia|bukalapak).*/;
  var precompiledRegex3 = /^(http|https):\/\/.+\.(facebook|youtube|yahoo|detik|liputan6|kaskus|tokopedia|bukalapak)/;
  var precompiledRegex4 = /^(http|https):\/\/.+\.(facebook|youtube|yahoo|detik|liputan6|kaskus|tokopedia|bukalapak).*/;
  var precompiledRegex5 = /^(.*)(facebook|youtube|yahoo|detik|liputan6|kaskus|tokopedia|bukalapak)/;
  var precompiledRegex6 = /^(.*)(facebook|youtube|yahoo|detik|liputan6|kaskus|tokopedia|bukalapak).*/;
  var precompiledRegex7 = /^(.*)(facebook|youtube|yahoo|detik||kaskus|bukalapak|kompas|wordpress|tokopedia|okezone|twitter|blogspot|blogger|lazada|instagram|suara|olx|kompasiana|tempo|sindonews|tribunnews|merdeka|bintang|elevenia|republika|viva|rimanews|cliponyu|metrotvnews|kapanlagi|uzone|pulsk|beritasatu).*/;

};
</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
test
precompiledRegex1.test(str);
pending…
search
precompiledRegex2.test(str);
pending…
match
/^(.*)(facebook|youtube|yahoo|detik|liputan6|kaskus|tokopedia|bukalapak)/.test(str);
pending…
indexOf
precompiledRegex3.test(str);
pending…
precompiled test
precompiledRegex4.test(str);
pending…
precompiled search
precompiledRegex5.test(str);
pending…
precompiled match
/^(.*)(facebook|youtube|yahoo|detik||kaskus|bukalapak|kompas|wordpress|tokopedia|okezone|twitter|blogspot|blogger|lazada|instagram|suara|olx|kompasiana|tempo|sindonews|tribunnews|merdeka|bintang|elevenia|republika|viva|rimanews|cliponyu|metrotvnews|kapanlagi|uzone|pulsk|beritasatu).*/.test(str);
pending…
precompiled indexOf
precompiledRegex6.test(str);
pending…
indexOf string primitive
precompiledRegex7.test(str);
pending…
Primitive comparison
/(http|https):\/\/.+\.(facebook|youtube|yahoo|detik|liputan6|kaskus|tokopedia|bukalapak)/.test(str);
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