javascript-find-all

JavaScript performance comparison

Test case created by Stuart Rutter

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
Using Regex
function indexes(str, find) {
  var regex = new RegExp(find, "g")
  ,   result
  ,   indices = [];
  while ((result = regex.exec(str))) {
    indices.push(result.index);
  }
  return indices;
}

indexes("I learned to play the Ukulele in Lebanon.", "le");
pending…
No Regex
function indexes(str, find) {
  var result = [];
  for (i = 0; i < str.length; ++i) {
    if (str.substring(i, i + find.length) == find) {
      result.push(i);
    }
  }
  return result;
}

indexes("I learned to play the Ukulele in Lebanon.", "le");
pending…

Compare results of other browsers

Revisions

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

0 Comments