Skip to content

Commit

Permalink
chore: update bench
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 20, 2024
1 parent a33a2e1 commit d0a83f9
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 177 deletions.
175 changes: 83 additions & 92 deletions BENCH.md
Original file line number Diff line number Diff line change
@@ -1,105 +1,96 @@
## Node.js

Running on Node.js `v20.9.0`

=== Non-string fallback ==
JSON.parse x 9,464,387 ops/sec ±0.19% (97 runs sampled)
destr x 255,562,708 ops/sec ±0.23% (98 runs sampled)
safeDestr x 74,229,966 ops/sec ±0.42% (93 runs sampled)
sjson:
@hapi/bourne x 9,019,413 ops/sec ±0.32% (96 runs sampled)
Fastest is destr

=== Known values ==
JSON.parse x 23,600,894 ops/sec ±0.44% (92 runs sampled)
destr x 78,297,469 ops/sec ±0.27% (98 runs sampled)
safeDestr x 40,300,751 ops/sec ±0.46% (98 runs sampled)
sjson x 16,228,475 ops/sec ±1.08% (94 runs sampled)
@hapi/bourne x 20,756,877 ops/sec ±0.56% (97 runs sampled)
Fastest is destr
```
cpu: Apple M2
runtime: node v20.11.1 (arm64-darwin)
=== plain string (short) ==
JSON.parse (try-catch) x 14,024,616 ops/sec ±0.37% (97 runs sampled)
destr x 47,234,367 ops/sec ±2.82% (90 runs sampled)
safeDestr x 32,067,177 ops/sec ±0.29% (97 runs sampled)
sjson (try-catch) x 10,652,731 ops/sec ±0.33% (97 runs sampled)
@hapi/bourne x 11,778,015 ops/sec ±1.12% (89 runs sampled)
Fastest is destr
benchmark time (avg) (min … max)
--------------------------------------------------------------
• Non-string fallback
--------------------------------------------------------------
destr 4.84 ns/iter (3.78 ns … 326 ns)
JSON.parse 174 ns/iter (139 ns … 701 ns)
safeDestr 31.18 ns/iter (18.41 ns … 337 ns)
sjson error: text.charCodeAt is not a function
TypeError: text.charCodeAt is not a function
@hapi/bourne 157 ns/iter (144 ns … 314 ns)
=== plain string (long) ==
JSON.parse (try-catch) x 156,139 ops/sec ±0.88% (93 runs sampled)
destr x 38,673,125 ops/sec ±0.35% (94 runs sampled)
safeDestr:
sjson (try-catch) x 323,817 ops/sec ±0.80% (96 runs sampled)
@hapi/bourne:
Fastest is destr
summary for Non-string fallback
destr
6.44x faster than safeDestr
32.41x faster than @hapi/bourne
35.96x faster than JSON.parse
=== package.json ==
JSON.parse x 357,325 ops/sec ±0.32% (98 runs sampled)
destr x 295,762 ops/sec ±0.32% (98 runs sampled)
safeDestr x 295,847 ops/sec ±0.13% (97 runs sampled)
sjson x 297,089 ops/sec ±0.35% (97 runs sampled)
@hapi/bourne x 323,762 ops/sec ±0.19% (97 runs sampled)
Fastest is JSON.parse
• Known values
--------------------------------------------------------------
destr 22.56 ns/iter (15.85 ns … 136 ns)
JSON.parse 95.87 ns/iter (89.92 ns … 227 ns)
safeDestr 50.85 ns/iter (30.92 ns … 537 ns)
sjson 113 ns/iter (109 ns … 266 ns)
@hapi/bourne 105 ns/iter (98.02 ns … 112 ns)
=== broken object ==
JSON.parse (try-catch) x 95,513 ops/sec ±0.50% (93 runs sampled)
destr x 84,278 ops/sec ±0.37% (95 runs sampled)
safeDestr:
sjson (try-catch) x 163,887 ops/sec ±0.69% (95 runs sampled)
@hapi/bourne:
Fastest is sjson (try-catch)
summary for Known values
destr
2.25x faster than safeDestr
4.25x faster than JSON.parse
4.64x faster than @hapi/bourne
5.02x faster than sjson
## Bun
• plain string (short)
--------------------------------------------------------------
destr 27.21 ns/iter (26.14 ns … 107 ns)
JSON.parse (try-catch) 120 ns/iter (115 ns … 292 ns)
safeDestr 62.07 ns/iter (41.56 ns … 720 ns)
sjson (try-catch) 148 ns/iter (135 ns … 475 ns)
@hapi/bourne 130 ns/iter (125 ns … 308 ns)
Runnin on Bun `v1.0.7`
summary for plain string (short)
destr
2.28x faster than safeDestr
4.4x faster than JSON.parse (try-catch)
4.79x faster than @hapi/bourne
5.43x faster than sjson (try-catch)
```
=== Non-string fallback ==
JSON.parse x 17,172,248 ops/sec ±2.51% (80 runs sampled)
destr x 70,028,734 ops/sec ±10.62% (50 runs sampled)
safeDestr x 26,543,362 ops/sec ±4.69% (70 runs sampled)
sjson:
@hapi/bourne x 14,412,494 ops/sec ±2.21% (82 runs sampled)
Fastest is destr
• plain string (long)
--------------------------------------------------------------
destr 567 ns/iter (34.57 ns … 1'001 ns)
JSON.parse (try-catch) 4'900 ns/iter (3'813 ns … 6'664 ns)
safeDestr 4'751 ns/iter (4'284 ns … 5'953 ns)
sjson (try-catch) 2'895 ns/iter (2'564 ns … 4'633 ns)
@hapi/bourne 6'528 ns/iter (5'767 ns … 8'859 ns)
=== Known values ==
JSON.parse x 37,889,947 ops/sec ±6.42% (63 runs sampled)
destr x 31,602,584 ops/sec ±4.29% (72 runs sampled)
safeDestr x 17,022,901 ops/sec ±3.09% (80 runs sampled)
sjson x 16,439,558 ops/sec ±2.63% (82 runs sampled)
@hapi/bourne x 25,914,930 ops/sec ±4.35% (69 runs sampled)
Fastest is JSON.parse
summary for plain string (long)
destr
5.11x faster than sjson (try-catch)
8.38x faster than safeDestr
8.64x faster than JSON.parse (try-catch)
11.52x faster than @hapi/bourne
=== plain string (short) ==
JSON.parse (try-catch) x 18,661,059 ops/sec ±2.92% (73 runs sampled)
destr x 15,789,374 ops/sec ±2.66% (80 runs sampled)
safeDestr x 10,512,090 ops/sec ±1.98% (83 runs sampled)
sjson (try-catch) x 10,938,015 ops/sec ±1.68% (87 runs sampled)
@hapi/bourne x 14,817,736 ops/sec ±2.66% (79 runs sampled)
Fastest is JSON.parse (try-catch)
• package.json
--------------------------------------------------------------
destr 3'900 ns/iter (3'739 ns … 4'597 ns)
JSON.parse 3'426 ns/iter (3'200 ns … 4'132 ns)
safeDestr 4'290 ns/iter (3'795 ns … 6'540 ns)
sjson 4'289 ns/iter (3'716 ns … 6'109 ns)
@hapi/bourne 3'636 ns/iter (3'464 ns … 4'400 ns)
=== plain string (long) ==
JSON.parse (try-catch) x 688,257 ops/sec ±0.39% (92 runs sampled)
destr x 14,458,797 ops/sec ±2.54% (82 runs sampled)
safeDestr:
sjson (try-catch) x 531,925 ops/sec ±1.27% (94 runs sampled)
@hapi/bourne:
Fastest is destr
summary for package.json
destr
1.14x slower than JSON.parse
1.07x slower than @hapi/bourne
1.1x faster than sjson
1.1x faster than safeDestr
=== package.json ==
JSON.parse x 405,237 ops/sec ±0.41% (96 runs sampled)
destr x 58,580 ops/sec ±0.21% (97 runs sampled)
safeDestr x 58,269 ops/sec ±0.21% (95 runs sampled)
sjson x 316,115 ops/sec ±0.38% (94 runs sampled)
@hapi/bourne x 351,669 ops/sec ±0.33% (98 runs sampled)
Fastest is JSON.parse
• broken object
--------------------------------------------------------------
destr 3'978 ns/iter (3'766 ns … 4'634 ns)
JSON.parse (try-catch) 3'478 ns/iter (3'199 ns … 4'281 ns)
safeDestr 3'953 ns/iter (3'800 ns … 5'057 ns)
sjson (try-catch) 3'930 ns/iter (3'724 ns … 4'593 ns)
@hapi/bourne 3'655 ns/iter (3'455 ns … 4'265 ns)
=== broken object ==
JSON.parse (try-catch) x 240,053 ops/sec ±0.56% (96 runs sampled)
destr x 52,153 ops/sec ±0.40% (93 runs sampled)
safeDestr:
sjson (try-catch) x 210,145 ops/sec ±0.39% (96 runs sampled)
@hapi/bourne:
Fastest is JSON.parse (try-catch)
summary for broken object
destr
1.14x slower than JSON.parse (try-catch)
1.09x slower than @hapi/bourne
1.01x slower than sjson (try-catch)
1.01x slower than safeDestr
```
81 changes: 0 additions & 81 deletions bench.mjs

This file was deleted.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"lib"
],
"scripts": {
"bench:bun": "pnpm build && bun --bun ./bench.mjs",
"bench:node": "pnpm build && node ./bench.mjs",
"bench:bun": "pnpm build && bun --bun ./test/bench.mjs",
"bench:node": "pnpm build && node ./test/bench.mjs",
"build": "unbuild",
"dev": "vitest dev",
"lint": "eslint --ext .ts . && prettier -c src test",
Expand All @@ -32,15 +32,15 @@
"devDependencies": {
"@hapi/bourne": "^3.0.0",
"@vitest/coverage-v8": "^1.3.0",
"benchmark": "^2.1.4",
"changelogen": "^0.5.5",
"eslint": "^8.56.0",
"eslint-config-unjs": "^0.2.1",
"mitata": "^0.1.11",
"prettier": "^3.2.5",
"secure-json-parse": "^2.7.0",
"typescript": "^5.3.3",
"unbuild": "^2.0.0",
"vitest": "^1.3.0"
},
"packageManager": "pnpm@8.15.3"
}
}
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d0a83f9

Please sign in to comment.