Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
parse nested keys
(version: 1)
Comparing performance of:
with regex vs with regex 2 vs without regex
Created:
6 months ago
by:
Registered User
Jump to the latest result
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")
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
with regex
with regex 2
without regex
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
6 months ago
)
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/OS:
Chrome 141 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
with regex
3665375.2 Ops/sec
with regex 2
5206278.5 Ops/sec
without regex
17701470.0 Ops/sec
Related benchmarks:
is unique
Access Object, Map, Set
Lodash.get vs safeGet vs get vs optional chaining vs youDontNeedGet
Lodash.get vs Lodash.property vs native test
Lodash.get vs safeGet vs Null operator
Nullish vs If
Nullish vs If 2 lvl
Object vs Map MYTEST2137
return or null
Comments
Confirm delete:
Do you really want to delete benchmark?