Test name | Executions per second |
---|---|
startsWith | 59.6 Ops/sec |
.charAt | 161.5 Ops/sec |
<div></div>
var data = window.data = [];
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
var TOTAL_STRINGS = window.TOTAL_STRINGS = 100000;
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
function makeRandomString(len) {
var text = "";
for( var i=0; i < len; i++ ) {
text += possible.charAt(getRandomInt(possible.length));
}
return text;
}
while (data.length < TOTAL_STRINGS) {
data.push(makeRandomString(getRandomInt(20)));
}
var x = 0;
var TOTAL_STRINGS = window.TOTAL_STRINGS;
var data = window.data;
var regex = window.regex;
while (x < TOTAL_STRINGS) {
const str = data[x];
str.startsWith("A");
x += 1;
}
var x = 0;
var TOTAL_STRINGS = window.TOTAL_STRINGS;
var data = window.data;
var match = window.match;
while (x < TOTAL_STRINGS) {
const str = data[x];
str.charAt(0) === 'A';
x += 1;
}