Test name | Executions per second |
---|---|
regex | 4949697.0 Ops/sec |
split | 6180327.5 Ops/sec |
for loop1 | 10303806.0 Ops/sec |
for loop 2 | 185075.1 Ops/sec |
deleting | 5308489.5 Ops/sec |
histogram | 68482.1 Ops/sec |
("this is foo bar".match(/o/g)||[]).length
"this is foo bar".split("o").length-1
var stringsearch = "o";
var str = "this is foo bar";
for(var count=-1,index=-2; index != -1; count++,index=str.indexOf(stringsearch,index+1) );
var stringsearch = "o";
var str = "this is foo bar";
for(var i=count=0; i<str.length; count+=+(stringsearch===str[i++]));
var str = "this is foo bar";
str.length - str.replace(/o/g,'').length;
var str = "this is foo bar";
var schar = 'o';
var hist={};
for(si in str){
hist[str[si]] = hist[str[si]] ? 1+hist[str[si]]:1;
}