Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Custom Build Query 2
(version: 1)
Comparing performance of:
URLSearchParams vs Custom (safe) vs Custom 2 (unsafe) vs Custom (fast)
Created:
one year ago
by:
Guest
Jump to the latest result
Script Preparation code:
var querystring = 'foo=bar&baz=qux&quxx=corge&grault=garply&waldo=fred&plugh=xyzzy' var queryobj = { foo: 'bar', baz: 'qux', quux: 'corge', grault: 'garply', waldo: 'fred', plugh: 'xyzzy' } function encode(data) { let result = '?' for (const key in data) { if (data[key] != null) { result += key + '=' + data[key] + '&' } } return result.slice(0, -1) } function encodeNative(data) { return new URLSearchParams(data).toString() } function buildQueryString(params) { const query = Object.entries(params) .filter(([_, value]) => value !== undefined && value !== null) .map(([key, value]) => `${key}=${encodeURIComponent(String(value))}`) .join('&'); return query ? `?${query}` : ''; } function fastBuildQueryString(params) { let result = '?'; let first = true; for (const key of Object.keys(params)) { const value = params[key]; if (value != null) { if (!first) result += '&'; result += key + '=' + encodeURIComponent(String(value)); first = false; } } return first ? '' : result; }
Tests:
URLSearchParams
encodeNative(queryobj)
Custom (safe)
buildQueryString(queryobj)
Custom 2 (unsafe)
encode(queryobj)
Custom (fast)
fastBuildQueryString(queryobj)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
URLSearchParams
Custom (safe)
Custom 2 (unsafe)
Custom (fast)
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.1 Safari/605.1.15
Browser/OS:
Safari 18 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
URLSearchParams
1544708.1 Ops/sec
Custom (safe)
1561038.0 Ops/sec
Custom 2 (unsafe)
5033470.0 Ops/sec
Custom (fast)
3234752.2 Ops/sec
Related benchmarks:
12121212212
URLSearchParams vs Custom
Map lookup or in operator
joined map or concatenate 3
zargazrgzragzra
set.has vs string equals
test123kjfhneurkgewrxfiewhlrugxerg123
Custom Build Query
Custom Build Query 3
Comments
Confirm delete:
Do you really want to delete benchmark?