contains() vs indexOf (v9)

Revision 9 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
!==
https: //www.facebook.com/homranibb
ready

Revisions

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