Regex vs Re-assignment

Benchmark created on


Description

Test created by @Logos

Setup

const regexWordSeparator = /\s+|\S+/g;
const regexError = /^@?[A-Za-z0-9_]{5,32}(\.tg)?$/;
const regexErrorSyntax = /^@?[A-Za-z0-9_]+(\.tg)?$/;

const text = 'aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba aboba abba';

let error1 = '';
let error2 = '';

Test runner

Ready to run.

Testing in
TestOps/sec
Regex
if (!regexError.test(text)) error1 = 'error';
if (!regexErrorSyntax.test(text)) error2 = 'error';

while (match = regexWordSeparator.exec(text)) {
  const matchText = match[0];
  const checkingError = !regexError.test(matchText);
}

console.log(error1)
console.log(error2)
ready
Re-assignment
while (match = regexWordSeparator.exec(text)) {
  const matchText = match[0];
  const checkingError = !regexError.test(matchText);
  error1 = 'error'
  error2 = 'error'
}

console.log(error1)
console.log(error2)
ready

Revisions

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