count-char-occurrences (v2)

Revision 2 of this benchmark created on


Test runner

Ready to run.

Testing in
TestOps/sec
String regex count matches1
var count = function(string, value) {
 return (string.length - string.replace(new RegExp(value, "g"), '').length) / value.length;
}
var string = "1.2.3";
count(string, "\.");
ready
String regex count matches
var count = function(string, match) {
 var res = string.match(new RegExp(match, "g"));
 if (res == null) {
  return 0;
 }
 return res.length;
}
var string = "1.2.3";
count(string, "\.");
ready
String split
var count = function(mainStr, match) {
 return mainStr.split(match).length - 1;
}
var string = "1.2.3";
count(string, ".");
ready

Revisions

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