RegExp test / search / match vs. indexOf (v63)

Revision 63 of this benchmark created by Cenas on


Preparation HTML

<script>
  var str = 'selected_payment js-paypal';
</script>

Setup

var regex = /(js-paypal)/i;

Test runner

Ready to run.

Testing in
TestOps/sec
test
if(/(js-paypal)/.test(str)){
}
ready
search
str.search(/(js-paypal)/) > -1;
ready
match
str.match(/(js-paypal)/i).length > 0;
ready
indexOf
str.indexOf(/(js-paypal)/i) > -1;
ready
precompiled test
regex.test(str);
ready
precompiled search
str.search(regex) > -1;
ready
precompiled match
str.match(regex).length > 0;
ready
precompiled indexOf
str.indexOf(regex) > -1;
ready
indexOf string primitive
str.toLowerCase().indexOf('js-paypal') > -1;
ready
Primitive comparison
if(regex.test(str)){
}
ready

Revisions

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