Skip to content

Commit eb60af1

Browse files
committedAug 2, 2023
chore: update benchmarks
1 parent ff5f331 commit eb60af1

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed
 

‎README.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -118,50 +118,50 @@ safeDestr("[foo");
118118

119119
## Benchmarks
120120

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.
122122

123123
**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.
124124

125125
```
126126
=== 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)
130130
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)
132132
Fastest is destr
133133
134134
=== 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)
140140
Fastest is destr
141141
142142
=== 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)
148148
Fastest is destr
149149
150150
=== 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)
156156
Fastest is JSON.parse
157157
158158
=== 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)
163+
@hapi/bourne:
164+
Fastest is sjson (try-catch)
165165
```
166166

167167
## License

0 commit comments

Comments
 (0)
Please sign in to comment.