Regex.exec with Long String vs. Regex.test with Long String Split into an Array

Benchmark created on


Setup

const Reggie = /0002\d{6}/g;
const longString =  `i\n\n. |\nMegatronic PACKING LisT |\nDelivery: 1419074157 - ' Page: 10f 1\nDate: 09-JUN-2023\n\ni\n\nDistributed from: Sold To: Ship To: |\n\nMegatronic Logistics LL.C 2222222 2222222 i\n\nShipment: 4340 Sweetpea Pod Bobalob of Swansea Medical Bobalob Of Swansea Medical !\nShipment Date:  09-JUN-2023 Swan Sea 38222-6603 1215 Decptical 29WHSDOCK |\nNumber of Pailets / Box: 1 USA The Glob 55555-55555, US Spartacus Pocket |\nAWB / Bill of Lading: Landsdown Toilet, US |\nOrder Date:  09-JUN-2023 |\nCarrier:  FXGQIY Ickabod Grain |\nSpackle Number: 651071925796\nSales Order /Line  item Number / CFN Material Description Serial / Batch uBb BackOrdQty\nOptimus PO GTIN Optimus ltem Number Hazardous Material Quantity / UOM\nOptimus Description )\ne i\n\n- e T\nNested SSCC Number $5CC Number Spackle Number Palet Volume Welght Delivery\n400000000107416927 339 L 39,800,908 CCM 1.446,051 G 1413074157\n\n6215634973/10 N180802 GW N180802 NITREX V04 8082911 01-MAR-2026 0\n0002306096 20763000185408 9003199677 6PK\nMessages to Optimus:\nVisit Connect.Megatronic.com for order history, involices, returns, and more. ) i\n\ni\n\n1 i\n\ni {\n\n! :\n\ni\n\ni\n\ni\n\n|\n"`
const words = longString.split(' ');
let matchArray = [];

Teardown

console.log(matchArray);

Test runner

Ready to run.

Testing in
TestOps/sec
Regex.exec on String
let execArray;
while ((execArray=Reggie.exec(longString)) !== null) {
	matchArray.push(execArray[0]);
};
console.log(matchArray);
ready
Regex.match on Array
matchArray = words.filter(value => Reggie.test(value));
console.log(matchArray);
ready

Revisions

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