RegExp vs indexOf (v23)

Revision 23 of this benchmark created on


Description

Compare speed of Regex with indexOf for simple string comparison

Test runner

Ready to run.

Testing in
TestOps/sec
Regex
var str = "asdasda @bırakg #sdsşds @dfgfd 6fg dfdfg dfgdfg #dfg";
var linkToBe = str.match(/[@#]\S*/g);
ready
indexOf
var str = "asdasda @bırakg #sdsşds @dfgfd 6fg dfdfg dfgdfg #dfg";

var tagsList = str.split(' ');
var linkToBe = [];
for (var i = 0; i < tagsList.length; i++) {
  if (tagsList[i].charAt(0) === '@' ||
    tagsList[i].charAt(0) === '#') {
    linkToBe.push(tagsList[i]);
  }
}
ready

Revisions

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