Skip to content

Commit 5201c04

Browse files
committed
perf: improve parse performance by 130k op/sec
1 parent 8b65d89 commit 5201c04

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ console.log(qs.stringify({ foo: ['bar', 'baz'] }))
4848
╔═════════════════════════════════════════╤═════════╤═══════════════════╤═══════════╗
4949
║ Slower tests │ Samples │ Result │ Tolerance ║
5050
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
51-
║ qs │ 10000 │ 310498.16 op/sec │ ± 1.40 % ║
52-
║ query-string │ 10000 │ 335094.41 op/sec │ ± 1.06 % ║
53-
║ querystringify │ 10000 │ 444913.68 op/sec │ ± 1.32 % ║
54-
║ @aws-sdk/querystring-parser │ 1000 │ 462867.39 op/sec │ ± 0.75 % ║
55-
║ URLSearchParams-with-Object.fromEntries │ 10000 │ 830585.13 op/sec │ ± 3.19 % ║
56-
║ URLSearchParams-with-construct │ 10000 │ 1216221.57 op/sec │ ± 3.46 % ║
57-
║ node:querystring │ 35001407749.94 op/sec │ ± 0.91 % ║
51+
║ qs │ 10000 │ 316071.64 op/sec │ ± 1.29 % ║
52+
║ query-string │ 10000 │ 334619.39 op/sec │ ± 1.43 % ║
53+
║ querystringify │ 10000 │ 448353.77 op/sec │ ± 1.42 % ║
54+
║ @aws-sdk/querystring-parser │ 1000 │ 480685.11 op/sec │ ± 0.78 % ║
55+
║ URLSearchParams-with-Object.fromEntries │ 10000 │ 833241.61 op/sec │ ± 2.97 % ║
56+
║ URLSearchParams-with-construct │ 10000 │ 1184116.36 op/sec │ ± 4.50 % ║
57+
║ node:querystring │ 30001435004.35 op/sec │ ± 0.93 % ║
5858
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
5959
║ Fastest test │ Samples │ Result │ Tolerance ║
6060
╟─────────────────────────────────────────┼─────────┼───────────────────┼───────────╢
61-
║ fast-querystring │ 10000 │ 1575870.52 op/sec │ ± 2.80 % ║
61+
║ fast-querystring │ 10000 │ 1706108.77 op/sec │ ± 4.66 % ║
6262
╚═════════════════════════════════════════╧═════════╧═══════════════════╧═══════════╝
6363
```
6464

lib/parse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function parse(input) {
2525

2626
// Have a boundary of input.length + 1 to access last pair inside the loop.
2727
for (let i = 0; i < inputLength + 1; i++) {
28-
let c = (i !== inputLength && input.charCodeAt(i)) || -1;
28+
let c = i !== inputLength ? input.charCodeAt(i) : -1;
2929

3030
// Handle '&' and end of line to pass the current values to result
3131
if (c === 38 || c === -1) {

0 commit comments

Comments
 (0)