String#match vs. RegExp#test

Benchmark created by Mathias Bynens on


Setup

var array = ['xn--lol', 'foo bar baz'];

Test runner

Ready to run.

Testing in
TestOps/sec
String#match
var length = array.length;
while (length--) {
  array[length].match(/^xn--/);
}
ready
RegExp#test
var length = array.length;
while (length--) {
  /^xn--/.test(array[length]);
}
ready

Revisions

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

  • Revision 1: published by Mathias Bynens on