Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Parsing window.location.search to object
(version: 6)
Finding the fastest way to parse window.location.search.
Comparing performance of:
Double splitting vs Regex mapping vs Regex looping vs Regex iterator
Created:
3 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var search = "?test=test2&test3=test4&test5=test6"; var regex = /[&\?]([^=]+)=([^&]+)/g;
Tests:
Double splitting
var params = {}; var query = search.substring(1); var paramStrs = query.split('&'); for (paramStr of paramStrs) { var pair = paramStr.split('='); params[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]); }
Regex mapping
var params = Object.fromEntries(new Map(Array.from(search.matchAll(regex)).map(match => [decodeURIComponent(match[1]), decodeURIComponent(match[2])])));
Regex looping
var params = {}; while((param = regex.exec(search)) !== null) { params[decodeURIComponent(param[1])] = decodeURIComponent(param[2]); }
Regex iterator
var params = {}; var regexMatches = search.matchAll(regex); while(!(current = regexMatches.next()).done) { var param = current.value; params[decodeURIComponent(param[1])] = decodeURIComponent(param[2]); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
Double splitting
Regex mapping
Regex looping
Regex iterator
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Related benchmarks:
get last element of path: split vs regex
regecxt
regecxgth
test split vs match regex
RegEx.test vs String.search js
Comments
Confirm delete:
Do you really want to delete benchmark?