Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Run results for:
parse nested keys
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/141.0.0.0 Safari/537.36
Browser:
Chrome 141
Operating system:
Windows
Device Platform:
Desktop
Date tested:
6 months ago
Test name
Executions per second
with regex
3665375.2 Ops/sec
with regex 2
5206278.5 Ops/sec
without regex
17701470.0 Ops/sec
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
/*your preparation JavaScript code goes here To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/ function parseKeys_1(path) { return path.split(".").flatMap((key) => { const match = key.match(/^([^[\]]+)(\[(\d+)\])?$/); if (!match) { throw new Error(`nestedProperty.set(). Invalid path segment: ${key}`); } return [match[1], match[3]].filter(Boolean); }); } function parseKeys_2(path) { return path .replace(/\[(\w+)\]/g, '.$1') // convert [0] to .0 .split('.') // split by dots .filter(Boolean); } function parsePath(path) { const keys = []; let start = 0; for (let i = 0; i < path.length; i++) { const c = path[i]; if (c === '.' || c === '[') { if (i > start) keys.push(path.substring(start, i)); if (c === '[') { const close = path.indexOf(']', i); if (close === -1) throw new Error("Unmatched ["); keys.push(path.substring(i + 1, close)); i = close; } start = i + 1; } } if (start < path.length) keys.push(path.substring(start)); return keys; }
Tests:
with regex
parseKeys_1("obj.items[0].value")
with regex 2
parseKeys_2("obj.items[0].value")
without regex
parsePath("obj.items[0].value")