regex.length vs split.length

Benchmark created by Paul Grenier on


Setup

var str = Array(12).join(".").split(".").map(function (e,i) {
      return Array.prototype.join.call({length:i}, ".");
    });

Test runner

Ready to run.

Testing in
TestOps/sec
regex
str.map(function (e) {
  return (e.match(/\./g) || []).length + 1;
});
ready
split
str.map(function (e) {
  return e.split(".").length;
});
ready

Revisions

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

  • Revision 1: published by Paul Grenier on