CVR/VAT Regex Performance Benchmark

Benchmark created on


Setup

const CvrPattern = /^(?:\d{11}|\d{2}\s\d{3}\s\d{3}\s\d{3}|\d{2}-\d{3}-\d{3}-\d{3}|ATU\d{8}|BE[0-1]\d{9}|BG\d{9,10}|\d{9}[A-Z]{2}\d{4}|\d{8}[0-9K]|HR\d{11}|CY\d{8}[A-Z]|CZ\d{8,10}|(DK)?\d{8}|\d{3}-\d{3}-\d{3}|EE\d{9}|FO\d{6}|FI\d{8}|FR[0-9A-Z]{2}\d{9}|DE\d{9}|EL\d{9}|HU\d{8}|[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][0-9][A-Z][0-9A-Z]|\d{2}.\d{3}.\d{3}.\d{1}-\d{3}.\d{3}|IE(\d{7}[A-Z]{1,2}|\d[A-Z]\d{5}[A-Z]|\d{8})|IT\d{11}|\d{12}|\d{13}|\d{12}|P\d{9}[A-Z]|LV\d{11}|LT(?:\d{9}|\d{12})|LU\d{8}|[A-Z](-\d{11}|\d{11})|MT\d{8}|[A-Z&Ñ]{3,4}\d{6}[0-9A-Z]{3}|MD\d{9}|NL\d{9}B\d{2}|NO\d{9}(MVA)|\d{11}|PH|PL\d{10}|PT\d{9}|RO\d{2,10}|\d{15}|[0-9]{8}[A-Z]|M\d{7}[A-Z]|[A-Z]{1,2}\d{7}[A-Z]|SK\d{10}|SI\d{8}|4\d{9}|\d{3}-\d{2}-\d{5}|(ES)?[A-Z]\d{7}(?:[0-9]|[A-Z])|SE\d{10}|SE\d{12}|CHE-?\d{3}.\d{3}.\d{3}(?:TVA|MWST|IVA)|\d{8}|\d{13}|\d{10}|\d{11}|\d{10}|\d{12}|\d{15}|(GB)?(?:\d{9}(?:\d{3})?|[A-Z]{2}\d{3})|\d{2}-\d{7}|\d{10}|\d{10}-\d{3}|((?!DK)(?!SE)[A-Z]{2})\d{8,12})$/;

// Test cases for jsPerf
const testCases = [
  '12345678901',
  '12 345 678 901',
  '12-345-678-901',
  'ATU12345678',
  'BE0123456789',
  'BG1234567890',
  '123456789AB1234',
  'HR12345678901',
  'CY12345678A',
  'CZ1234567890',
  'DK12345678',
  '123-456-789',
  'invalid-input',
  'GB123456789012',
  'CHE123.456.789TVA',
  '12.345.678.9-123.456',
  'A'.repeat(1000) + '12345678901', // Long invalid input
  '123456789012345',
  'NL123456789B01',
  'SE123456789012'
];

// Setup function for jsPerf - runs once before benchmarking
function setup() {
  // Any setup code here, e.g., compile regex if needed
  // In JS, regex is already compiled when defined as literal
}

Test runner

Ready to run.

Testing in
TestOps/sec
test1
// Test 1: Basic regex test on all cases
function testRegexBasic() {
  for (let input of testCases) {
    CvrPattern.test(input);
  }
}
ready
test2
// Test 2: Just regex match (alternative to test)
function testRegexMatch() {
  for (let input of testCases) {
    CvrPattern.exec(input);
  }
}
ready
test3
// Test 5: Long input test
function testLongInput() {
  CvrPattern.test('A'.repeat(1000) + '12345678901');
}
ready

Revisions

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