Set vs Regex

Benchmark created on


Setup

const strings = [
'TR1',
'TR2',
'TR3',
'TR4',
'TR5',
'TR6',
'TR7',
'SW1',
'SW2',
'SW3',
'SW4',
'SW5',
'SW6',
'SW7',
'SW8',
'SW9',
'SW10',
'SW11',
'SW12',
'SW13',
];

const set = new Set(strings);
const regex = new RegExp(`^(?:${strings.join('|')})$`);

Test runner

Ready to run.

Testing in
TestOps/sec
Set
const matchResult = set.has('TR4');
const mismatchResult = set.has('none');
ready
Regex
const matchResult = regex.test('TR4');
const mismatchResult = regex.test('none');
ready

Revisions

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