indexof vs split

Benchmark created by Simo on


Setup

var canSplit1 = function(str, token){
        return (str || '').split(token).length > 1;         
    }
    
    var canSplit2 = function(str, token){
        return (str || '').indexOf(token) > -1;         
    }

Test runner

Ready to run.

Testing in
TestOps/sec
indexOf()
canSplit2('test if this works', 'if'); // returns true

canSplit2('test that this fails', 'if'); // returns false
ready
split()
canSplit1('test if this works', 'if'); // returns true

canSplit1('test that this fails', 'if'); // returns false
ready

Revisions

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

  • Revision 1: published by Simo on