contains() vs indexOf (v2)

Revision 2 of this benchmark created by RubaXa on


Setup

if (!String.prototype.contains) {
      String.prototype.contains = function(searchString, offset) {
        return this.indexOf(searchString, offset) !== -1;
      };
    }
    
    var string = 'foobarfoobar';

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf
string.indexOf('rf') != -1;
ready
contains
string.contains('rf');
ready
~string.indexOf
~string.indexOf('rf');
ready

Revisions

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