contains() vs indexOf (v13)

Revision 13 of this benchmark created by ES on


Preparation HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>

Setup

'use strict';
    
    if (!String.prototype.contains) {
      String.prototype.contains = function(searchString) {
        return this.indexOf(searchString) !== -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
>= 0
string.indexOf('rf') >= 0;
ready
+ 1
string.indexOf('rf') + 1;
ready
> -1
string.indexOf('rf') > -1;
ready
LoDash
_.contains(string, 'rf');
ready

Revisions

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