You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-26
Original file line number
Diff line number
Diff line change
@@ -118,50 +118,50 @@ safeDestr("[foo");
118
118
119
119
## Benchmarks
120
120
121
-
Locally try with `pnpm benchmark`. Below are esults on Node.js **v18.16.0** with MBA M2.
121
+
Locally try with `pnpm benchmark`. Below are esults on Node.js **v20.5.0** with MBA M2.
122
122
123
123
**Note**`destr` is sometimes little bit slower than `JSON.parse` when parsing a valid JSON string mainly because of transform to avoid [prototype pollution](https://learn.snyk.io/lessons/prototype-pollution/javascript/) which can lead to serious security issues if not being sanitized. In the other words, `destr` is better when input is not always a json string or from untrusted source like request body.
124
124
125
125
```
126
126
=== Non-string fallback ==
127
-
JSON.parse x 9,498,532 ops/sec ±0.57% (96 runs sampled)
128
-
destr x 153,323,211 ops/sec ±0.13% (99 runs sampled)
129
-
safeDestr x 64,237,062 ops/sec ±0.22% (96 runs sampled)
127
+
JSON.parse x 9,506,702 ops/sec ±1.68% (92 runs sampled)
128
+
destr x 159,565,446 ops/sec ±0.24% (98 runs sampled)
129
+
safeDestr x 73,624,106 ops/sec ±0.39% (95 runs sampled)
130
130
sjson:
131
-
@hapi/bourne x 9,190,459 ops/sec ±0.50% (93 runs sampled)
131
+
@hapi/bourne x 9,404,463 ops/sec ±0.62% (96 runs sampled)
132
132
Fastest is destr
133
133
134
134
=== Known values ==
135
-
JSON.parse x 14,260,909 ops/sec ±0.54% (95 runs sampled)
136
-
destr x 72,916,945 ops/sec ±0.15% (98 runs sampled)
137
-
safeDestr x 36,544,906 ops/sec ±0.31% (98 runs sampled)
138
-
sjson x 11,157,730 ops/sec ±0.53% (96 runs sampled)
139
-
@hapi/bourne x 13,241,853 ops/sec ±0.73% (93 runs sampled)
135
+
JSON.parse x 15,000,474 ops/sec ±0.82% (93 runs sampled)
136
+
destr x 96,977,026 ops/sec ±0.13% (101 runs sampled)
137
+
safeDestr x 47,618,310 ops/sec ±0.15% (98 runs sampled)
138
+
sjson x 11,176,069 ops/sec ±0.47% (93 runs sampled)
139
+
@hapi/bourne x 14,650,782 ops/sec ±0.64% (93 runs sampled)
140
140
Fastest is destr
141
141
142
142
=== plain string ==
143
-
JSON.parse (try-catch) x 10,603,912 ops/sec ±0.75% (91 runs sampled)
144
-
destr x 82,123,481 ops/sec ±2.37% (99 runs sampled)
145
-
safeDestr x 40,737,935 ops/sec ±0.97% (96 runs sampled)
146
-
sjson (try-catch) x 9,194,305 ops/sec ±1.96% (94 runs sampled)
147
-
@hapi/bourne x 10,816,232 ops/sec ±1.59% (90 runs sampled)
143
+
JSON.parse (try-catch) x 11,775,641 ops/sec ±0.64% (95 runs sampled)
144
+
destr x 111,118,106 ops/sec ±0.53% (101 runs sampled)
145
+
safeDestr x 52,455,654 ops/sec ±0.21% (97 runs sampled)
146
+
sjson (try-catch) x 9,282,956 ops/sec ±0.47% (96 runs sampled)
147
+
@hapi/bourne x 11,547,144 ops/sec ±0.68% (96 runs sampled)
148
148
Fastest is destr
149
149
150
150
=== package.json ==
151
-
JSON.parse x 403,428 ops/sec ±0.31% (101 runs sampled)
152
-
destr x 338,668 ops/sec ±0.27% (97 runs sampled)
153
-
safeDestr x 335,756 ops/sec ±0.29% (98 runs sampled)
154
-
sjson x 355,493 ops/sec ±0.15% (101 runs sampled)
155
-
@hapi/bourne x 384,948 ops/sec ±0.24% (98 runs sampled)
151
+
JSON.parse x 420,496 ops/sec ±0.20% (98 runs sampled)
152
+
destr x 358,257 ops/sec ±0.58% (98 runs sampled)
153
+
safeDestr x 351,278 ops/sec ±1.10% (98 runs sampled)
154
+
sjson x 358,003 ops/sec ±0.14% (102 runs sampled)
155
+
@hapi/bourne x 398,852 ops/sec ±0.32% (99 runs sampled)
156
156
Fastest is JSON.parse
157
157
158
158
=== broken object ==
159
-
JSON.parse (try-catch) x 406,262 ops/sec ±0.18% (100 runs sampled)
160
-
destr x 337,602 ops/sec ±0.37% (99 runs sampled)
161
-
safeDestr x 320,071 ops/sec ±0.35% (97 runs sampled)
162
-
sjson (try-catch) x 326,689 ops/sec ±0.41% (97 runs sampled)
163
-
@hapi/bourne x 313,024 ops/sec ±0.91% (94 runs sampled)
164
-
Fastest is JSON.parse (try-catch)
159
+
JSON.parse (try-catch) x 137,788 ops/sec ±0.68% (98 runs sampled)
160
+
destr x 111,878 ops/sec ±0.50% (98 runs sampled)
161
+
safeDestr:
162
+
sjson (try-catch) x 219,924 ops/sec ±0.62% (98 runs sampled)
0 commit comments