Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
parsing query param keys with string or regex
(version: 1)
Comparing performance of:
string parser vs regex parser
Created:
one month ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<!--your preparation HTML code goes here-->
Script Preparation code:
const params = { 'key[subKey1]': 'value1', 'key[subKey2]': 'value2', 'otherKey': 'otherValue', 'key2[subKey3]': 'value3', 'key2[subKey4]': 'value4', }; const key = 'key2';
Tests:
string parser
const value = {} for (const paramKey in params) { if (paramKey.startsWith(`${key}[`) && paramKey.endsWith(']')) { const subKey = paramKey.substring(key.length + 1, paramKey.length - 1); value[subKey] = params[paramKey]; } }
regex parser
const value = {} for (const paramKey in params) { // regex: const match = paramKey.match(new RegExp(`^${key}\\[(.+)\\]$`)) if (match) { value[match[1]] = params[paramKey]; } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
string parser
regex parser
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one month ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36 Edg/146.0.0.0
Browser/OS:
Chrome 146 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
string parser
7149721.0 Ops/sec
regex parser
1384794.6 Ops/sec
Related benchmarks:
test-foreach
regex split
destructuring vs creating
Test 03
startWith/includes
pick by substring key fixed
pick by substring key and concatenate
filter unsafe token
filter unsafe token 10w
Comments
Confirm delete:
Do you really want to delete benchmark?