RegExp test / search / match vs. indexOf

JavaScript performance comparison

Revision 63 of this test case created by Cenas

Preparation code

<script>
  var str = 'selected_payment js-paypal';
</script>
      
<script>
Benchmark.prototype.setup = function() {
  var regex = /(js-paypal)/i;

};
</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
if(/(js-paypal)/.test(str)){
}
pending…
search
str.search(/(js-paypal)/) > -1;
pending…
match
str.match(/(js-paypal)/i).length > 0;
pending…
indexOf
str.indexOf(/(js-paypal)/i) > -1;
pending…
precompiled test
regex.test(str);
pending…
precompiled search
str.search(regex) > -1;
pending…
precompiled match
str.match(regex).length > 0;
pending…
precompiled indexOf
str.indexOf(regex) > -1;
pending…
indexOf string primitive
str.toLowerCase().indexOf('js-paypal') > -1;
pending…
Primitive comparison
if(regex.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