Speed: aa? vs a+

Benchmark created on


Description

I think it's obvious that "aa?" is faster, cos it's just 1 or 2 symbols, but let's check that.

Test runner

Ready to run.

Testing in
TestOps/sec
a+
// Test 1: a+
const testAplus = () => {
  const regex = /a+/;
  return regex.test("a") && regex.test("aa") && regex.test("aaa");
};
ready
aa?
// Test 2: aa?
const testAAoptional = () => {
  const regex = /aa?/;
  return regex.test("a") && regex.test("aa") && !regex.test("aaa"); // Note: Fails on "aaa"
};
ready

Revisions

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