regex test vs match vs search

Benchmark created on


Description

Is a expansion on https://jsperf.app/test-vs-match-regex

Setup

var numbersRegex = /^\d+$/
  var noWhiteSpaceRegex = /^\S*$/
  var positveIntegerRegex = /^[0-9]\d*$/
  
  var number = "234524543";
  var white = "545mmckdddjl..21][a/z''";
  var positiveInteger = "-423.123";
  var x = 0;

Test runner

Ready to run.

Testing in
TestOps/sec
test
if (numbersRegex.test(number)) x++;

if (noWhiteSpaceRegex.test(white)) x++;

if (positveIntegerRegex.test(positiveInteger)) x++;
ready
match
if (number.match(numbersRegex)) x++;

if (white.match(noWhiteSpaceRegex)) x++;

if (positiveInteger.match(positveIntegerRegex)) x++;
ready
search
if (number.search(numbersRegex) !== -1) x++;

if (white.search(noWhiteSpaceRegex) !== -1) x++;

if (positiveInteger.search(positveIntegerRegex) !== -1) x++;
ready

Revisions

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