match vs others v2

Benchmark created on


Setup

var testString1 = "C0001";
var testString2 = "Q0001";

function testMatch(str) {
  return str.match(/^C/) !== null;
}

function testCharAt(str) {
  return str.charAt(0) === 'C';
}

function testProp(str) {
  return str[0] === 'C';
}

function testSubstr(str) {
  return str.substr(0,1) === 'C';
}

function testSubstring(str) {
  return str.substring(0,1) === 'C';
}

function testSlice(str) {
  return str.slice(0,1) === 'C';
}

function testTest(str) {
  return /^C/.test(str);
}

Test runner

Ready to run.

Testing in
TestOps/sec
match
testMatch(testString1);
testMatch(testString2);
ready
charAt
testCharAt(testString1);
testCharAt(testString2);
ready
prop
testProp(testString1);
testProp(testString2);
ready
substr
testSubstr(testString1);
testSubstr(testString2);
ready
substring
testSubstring(testString1);
testSubstring(testString2);
ready
slice
testSlice(testString1);
testSlice(testString2);
ready
test
testTest(testString1);
testTest(testString2);
ready

Revisions

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