contains() vs indexOf (v4)

Revision 4 of this benchmark created on


Setup

'use strict';
    
    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
!==
string.indexOf('rf') !== -1;
ready

Revisions

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