Regex Comparison: ([abc]) vs (a|b|c)

Benchmark created on


Description

Compare performance of two regex patterns for matching single characters.

Preparation HTML

const testStr = "banana";

Setup

// No setup needed for this simple test

Teardown

// No cleanup needed

Test runner

Ready to run.

Testing in
TestOps/sec
Square
// Test Case 1: ([abc])
const test1 = () => {
  const regex = /([abc])/;
  return regex.test("a") && regex.test("b") && regex.test("c");
};
ready
Normal
// Test Case 2: (a|b|c)
const test2 = () => {
  const regex = /(a|b|c)/;
  return regex.test("a") && regex.test("b") && regex.test("c");
};
ready

Revisions

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