string.split vs. indexOf (v10)

Revision 10 of this benchmark created on


Preparation HTML

<p id='test' class='one two three'>TEST</p>

Setup

var theEl = document.getElementById("test"),
    theClass = theEl.className;

Test runner

Ready to run.

Testing in
TestOps/sec
string.match
if (theClass.match('two')) { return true; }
ready
string.split
var classes = theClass.split(' '),
i = 0;

for (i = 0; i < classes.length; i++) {
if (classes[i] === theClass) { return true; }
}
ready
indexOf
if (theClass.indexOf('two') > -1) { return true; }
ready

Revisions

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