Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
Search words/regexes in string: matchAll vs split
Go to the benchmark
Embed
Embed Benchmark Result
Run details:
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36
Browser:
Chrome 137
Operating system:
Windows
Device Platform:
Desktop
Date tested:
11 months ago
Test name
Executions per second
regex
446627.8 Ops/sec
includes
143480.5 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
function generateRandomText(length) { const chars = 'abcdefghijklmnopqrstuvwxyz0123456789., '; let result = ''; for (let i = 0; i < length; i++) { const randomIndex = Math.floor(Math.random() * chars.length); result += chars[randomIndex]; } return result; } const test = generateRandomText(1000) const literalSearch = ["tg", "reg", "ha", "yo","mnasiwk"].sort( (a, b) => b.length - a.length ); const regSearch = ["c\\d", "a.{3}a", "<.+>", "^g.?a$"].sort( (a, b) => b.length - a.length ); const inc = regSearch.map(r => new RegExp(r)).concat(literalSearch); const regArr = regSearch.concat(literalSearch) const reg = new RegExp("(" + regArr.join(")|(") + ")", "g"); function regexMethod(str) { const res = {} for (const match of str.matchAll(reg)) { for (let i = 1; i <= regArr.length; i++) { if (!!match[i]) { res[regArr[i-1]] = (res[regArr[i-1]] ?? 0) + 1 break; } } } return res } function includeMethod(strArr) { const res = {} let nextArr = [] for (const sep of inc) { for (const str of strArr) { const parts = str.split(sep); if (parts.length !== 1) res[sep.source ?? sep] = (res[sep.source ?? sep] ?? 0) + parts.length - 1 nextArr.push(...parts) } strArr = nextArr; nextArr = []; } return res }
Tests:
regex
regexMethod(test)
includes
includeMethod([test])