Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update readme benchmarks
Browse files Browse the repository at this point in the history
Gobd committed Jan 12, 2025

Verified

This commit was signed with the committer’s verified signature.
1 parent 7e6da9f commit 9c05fa5
Showing 2 changed files with 201 additions and 115 deletions.
286 changes: 178 additions & 108 deletions README.md
Original file line number Diff line number Diff line change
@@ -295,86 +295,126 @@ JWKS is supported via [get-jwks](https://github.com/nearform/get-jwks). Check ou
### Signing
```
╔══════════════════════════════╤═════════╤═════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟──────────────────────────────┼─────────┼─────────────────┼───────────┼─────────────────────────╢
HS512 - fast-jwt (async) │ 1000055766.29 op/sec │ ± 2.85 % │ ║
HS512 - jsonwebtoken (async) │ 1000068764.89 op/sec │ ± 1.25 %+ 23.31 %
HS512 - jsonwebtoken (sync) │ 1000070191.14 op/sec │ ± 1.84 %+ 25.87 %
HS512 - jose (sync) │ 1000072844.84 op/sec │ ± 1.72 %+ 30.63 %
╟──────────────────────────────┼─────────┼─────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟──────────────────────────────┼─────────┼─────────────────┼───────────┼─────────────────────────╢
HS512 - fast-jwt (sync) │ 1000097602.16 op/sec │ ± 1.83 %+ 75.02 %
╚══════════════════════════════╧═════════╧═════════════════╧═══════════╧═════════════════════════╝

╔══════════════════════════════╤═════════╤═══════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟──────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
ES512 - fast-jwt (async) │ 1000419.29 op/sec │ ± 0.34 % │ ║
ES512 - jsonwebtoken (async) │ 1000440.53 op/sec │ ± 0.26 %+ 5.07 %
ES512 - jsonwebtoken (sync) │ 1000445.91 op/sec │ ± 0.16 %+ 6.35 %
ES512 - jose (sync) │ 1000452.01 op/sec │ ± 0.20 %+ 7.80 %
╟──────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟──────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
ES512 - fast-jwt (sync) │ 1000467.54 op/sec │ ± 0.15 %+ 11.51 %
╚══════════════════════════════╧═════════╧═══════════════╧═══════════╧═════════════════════════╝

╔══════════════════════════════╤═════════╤═══════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟──────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
RS512 - fast-jwt (async) │ 1000196.13 op/sec │ ± 0.28 % │ ║
RS512 - jsonwebtoken (async) │ 1000200.15 op/sec │ ± 0.23 %+ 2.05 %
RS512 - jsonwebtoken (sync) │ 1000203.72 op/sec │ ± 0.18 %+ 3.87 %
RS512 - jose (sync) │ 1000245.89 op/sec │ ± 0.39 %+ 25.37 %
╟──────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟──────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
RS512 - fast-jwt (sync) │ 1000273.31 op/sec │ ± 0.27 %+ 39.36 %
╚══════════════════════════════╧═════════╧═══════════════╧═══════════╧═════════════════════════╝

╔══════════════════════════════╤═════════╤═══════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟──────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
PS512 - jsonwebtoken (sync) │ 1000194.00 op/sec │ ± 0.27 % │ ║
PS512 - jsonwebtoken (async) │ 1000202.08 op/sec │ ± 0.21 %+ 4.17 %
PS512 - fast-jwt (async) │ 1000203.36 op/sec │ ± 0.19 %+ 4.82 %
PS512 - jose (sync) │ 1000266.54 op/sec │ ± 0.29 %+ 37.39 %
╟──────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟──────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
PS512 - fast-jwt (sync) │ 1000272.11 op/sec │ ± 0.24 %+ 40.26 %
╚══════════════════════════════╧═════════╧═══════════════╧═══════════╧═════════════════════════╝

╔══════════════════════════╤═════════╤═════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟──────────────────────────┼─────────┼─────────────────┼───────────┼─────────────────────────╢
║ EdDSA - fast-jwt (async) │ 10008301.50 op/sec │ ± 0.70 % │ ║
║ EdDSA - jose (sync) │ 150016561.83 op/sec │ ± 0.88 %+ 99.50 %
╟──────────────────────────┼─────────┼─────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟──────────────────────────┼─────────┼─────────────────┼───────────┼─────────────────────────╢
║ EdDSA - fast-jwt (sync) │ 300017514.99 op/sec │ ± 0.94 %+ 110.99 %
╚══════════════════════════╧═════════╧═════════════════╧═══════════╧═════════════════════════╝
╔═══════════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
HS256 - @node-rs/jsonwebtoken (async) │ 100074045.03 op/sec │ ± 0.85 % │ ║
HS256 - fast-jwt (async) │ 10000251884.32 op/sec │ ± 3.64 %+ 240.18 %
HS256 - jsonwebtoken (async) │ 10000282072.80 op/sec │ ± 1.43 %+ 280.95 %
HS256 - jsonwebtoken (sync) │ 10000323356.89 op/sec │ ± 1.64 %+ 336.70 %
HS256 - jose (sync) │ 10000329714.63 op/sec │ ± 2.45 %+ 345.29 %
HS256 - @node-rs/jsonwebtoken (sync) │ 1000360375.55 op/sec │ ± 0.53 %+ 386.70 %
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
HS256 - fast-jwt (sync) │ 10000431801.82 op/sec │ ± 2.52 %+ 483.16 %
╚═══════════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝

╔═══════════════════════════════════════╤═════════╤═══════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
RS256 - fast-jwt (async) │ 1000227.29 op/sec │ ± 0.39 % │ ║
RS256 - jsonwebtoken (async) │ 1000300.52 op/sec │ ± 0.13 %+ 32.22 %
RS256 - fast-jwt (sync) │ 1000302.37 op/sec │ ± 0.13 %+ 33.04 %
RS256 - jsonwebtoken (sync) │ 1000302.46 op/sec │ ± 0.13 %+ 33.07 %
RS256 - jose (sync) │ 1000302.49 op/sec │ ± 0.13 %+ 33.09 %
RS256 - @node-rs/jsonwebtoken (sync) │ 1000309.88 op/sec │ ± 0.49 %+ 36.34 %
╟───────────────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
RS256 - @node-rs/jsonwebtoken (async) │ 1000314.77 op/sec │ ± 0.03 %+ 38.49 %
╚═══════════════════════════════════════╧═════════╧═══════════════╧═══════════╧═════════════════════════╝

╔═══════════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
HS512 - @node-rs/jsonwebtoken (async) │ 150082025.83 op/sec │ ± 0.87 % │ ║
HS512 - fast-jwt (async) │ 10000247946.30 op/sec │ ± 3.34 %+ 202.28 %
HS512 - jsonwebtoken (async) │ 10000257520.13 op/sec │ ± 1.61 %+ 213.95 %
HS512 - jose (sync) │ 1500285727.62 op/sec │ ± 0.93 %+ 248.34 %
HS512 - @node-rs/jsonwebtoken (sync) │ 8000291709.90 op/sec │ ± 0.97 %+ 255.63 %
HS512 - jsonwebtoken (sync) │ 1000294312.24 op/sec │ ± 0.72 %+ 258.80 %
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
HS512 - fast-jwt (sync) │ 10000369219.80 op/sec │ ± 3.20 %+ 350.13 %
╚═══════════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝

╔═══════════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
ES512 - fast-jwt (async) │ 1500612.25 op/sec │ ± 0.72 % │ ║
ES512 - jsonwebtoken (async) │ 1000738.52 op/sec │ ± 0.06 %+ 20.62 %
ES512 - jsonwebtoken (sync) │ 1000738.90 op/sec │ ± 0.06 %+ 20.69 %
ES512 - jose (sync) │ 1000740.12 op/sec │ ± 0.04 %+ 20.89 %
ES512 - fast-jwt (sync) │ 1000743.13 op/sec │ ± 0.05 %+ 21.38 %
ES512 - @node-rs/jsonwebtoken (async) │ 150076321.13 op/sec │ ± 0.72 %+ 12365.75 %
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
ES512 - @node-rs/jsonwebtoken (sync) │ 7000335482.59 op/sec │ ± 0.94 %+ 54695.32 %
╚═══════════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝

╔═══════════════════════════════════════╤═════════╤═══════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
RS512 - fast-jwt (async) │ 1000232.20 op/sec │ ± 0.06 % │ ║
RS512 - jsonwebtoken (async) │ 1000301.91 op/sec │ ± 0.13 %+ 30.02 %
RS512 - fast-jwt (sync) │ 1000302.16 op/sec │ ± 0.13 %+ 30.13 %
RS512 - jose (sync) │ 1000302.18 op/sec │ ± 0.13 %+ 30.14 %
RS512 - jsonwebtoken (sync) │ 1000302.24 op/sec │ ± 0.13 %+ 30.16 %
RS512 - @node-rs/jsonwebtoken (async) │ 1000314.80 op/sec │ ± 0.03 %+ 35.57 %
╟───────────────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
RS512 - @node-rs/jsonwebtoken (sync) │ 1000316.38 op/sec │ ± 0.04 %+ 36.25 %
╚═══════════════════════════════════════╧═════════╧═══════════════╧═══════════╧═════════════════════════╝

╔═══════════════════════════════════════╤═════════╤═══════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
PS512 - fast-jwt (async) │ 1000232.20 op/sec │ ± 0.05 % │ ║
PS512 - fast-jwt (sync) │ 1000301.36 op/sec │ ± 0.13 %+ 29.78 %
PS512 - jsonwebtoken (sync) │ 1000301.69 op/sec │ ± 0.13 %+ 29.92 %
PS512 - jsonwebtoken (async) │ 1000301.94 op/sec │ ± 0.13 %+ 30.03 %
PS512 - jose (sync) │ 1000302.37 op/sec │ ± 0.13 %+ 30.22 %
PS512 - @node-rs/jsonwebtoken (async) │ 1000314.08 op/sec │ ± 0.03 %+ 35.26 %
╟───────────────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼───────────────┼───────────┼─────────────────────────╢
PS512 - @node-rs/jsonwebtoken (sync) │ 1000315.26 op/sec │ ± 0.04 %+ 35.77 %
╚═══════════════════════════════════════╧═════════╧═══════════════╧═══════════╧═════════════════════════╝

╔═══════════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ EdDSA - fast-jwt (async) │ 10003693.63 op/sec │ ± 0.20 % │ ║
║ EdDSA - jose (sync) │ 150031921.02 op/sec │ ± 0.74 %+ 764.22 %
║ EdDSA - fast-jwt (sync) │ 100033336.06 op/sec │ ± 0.94 %+ 802.53 %
║ EdDSA - @node-rs/jsonwebtoken (async) │ 100074783.37 op/sec │ ± 0.90 %+ 1924.66 %
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟───────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ EdDSA - @node-rs/jsonwebtoken (sync) │ 8500349524.57 op/sec │ ± 0.95 %+ 9362.91 %
╚═══════════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝
```
### Decoding
```
╔═════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
RS512 - jsonwebtoken - complete 10000126201.23 op/sec │ ± 2.84 % │ ║
RS512 - jsonwebtoken 10000143571.03 op/sec │ ± 1.82 %+ 13.76 %
RS512 - jose - complete 10000252738.76 op/sec │ ± 5.62 %+ 100.27 %
RS512 - fast-jwt │ 10000254921.59 op/sec │ ± 3.39 %+ 102.00 %
RS512 - jose │ 10000266197.51 op/sec │ ± 4.02 %+ 110.93 %
╟─────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
RS512 - fast-jwt - complete │ 10000284719.82 op/sec │ ± 3.39 %+ 125.61 %
╚═════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝
╔═════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
RS512 - jsonwebtoken 10000 498316.98 op/sec │ ± 1.48 % │ ║
RS512 - jsonwebtoken (complete) 10000 507533.27 op/sec │ ± 1.52 %+ 1.85 %
RS512 - fast-jwt (complete)10000 786208.40 op/sec │ ± 2.33 %+ 57.77 %
RS512 - fast-jwt │ 10000 838610.85 op/sec │ ± 1.42 %+ 68.29 %
RS512 - jose │ 1000957739.73 op/sec │ ± 0.88 %+ 92.19 %
╟─────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
RS512 - jose (complete) 100001034359.78 op/sec │ ± 2.44 %+ 107.57 %
╚═════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝
```
Note that for decoding the algorithm is irrelevant, so only one was measured.
@@ -385,74 +425,104 @@ Note that for decoding the algorithm is irrelevant, so only one was measured.
╔═════════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
HS512 - jsonwebtoken (sync) │ 1000049275.12 op/sec │ ± 1.41 % │ ║
HS512 - fast-jwt (async) 10000 51353.81 op/sec │ ± 2.98 %+ 4.22 %
HS512 - jsonwebtoken (async) │ 10000 51610.98 op/sec │ ± 1.51 %+ 4.74 %
HS512 - jose (sync) │ 10000 64280.92 op/sec │ ± 1.73 %+ 30.45 %
HS512 - fast-jwt (sync) │ 10000 75067.57 op/sec │ ± 2.40 %+ 52.34 %
HS512 - fast-jwt (async with cache) │ 10000175013.21 op/sec │ ± 4.42 %+ 255.18 %
HS256 - fast-jwt (async) 1000220491.56 op/sec │ ± 0.78 % │ ║
HS256 - jsonwebtoken (async) │ 10000235808.20 op/sec │ ± 1.17 %+ 6.95 %
HS256 - jsonwebtoken (sync) 10000252426.21 op/sec │ ± 1.62 %+ 14.48 %
HS256 - jose (sync) │ 10000278758.24 op/sec │ ± 2.26 %+ 26.43 %
HS256 - fast-jwt (sync) │ 10000339960.06 op/sec │ ± 2.86 %+ 54.18 %
HS256 - fast-jwt (async with cache) │ 10000733415.12 op/sec │ ± 6.67 %+ 232.63 %
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
HS512 - fast-jwt (sync with cache) │ 10000207199.64 op/sec │ ± 3.15 %+ 320.50 %
HS256 - fast-jwt (sync with cache) │ 7000986486.40 op/sec │ ± 0.96 %+ 347.40 %
╚═════════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝

╔═════════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
ES512 - fast-jwt (async) │ 1000 561.01 op/sec │ ± 0.44 % │ ║
ES512 - jsonwebtoken (sync) 1000 573.52 op/sec │ ± 0.27 %+ 2.23 %
ES512 - jsonwebtoken (async) │ 1000 573.74 op/sec │ ± 0.26 %+ 2.27 %
ES512 - fast-jwt (sync) │ 1000 597.68 op/sec │ ± 0.30 %+ 6.54 %
ES512 - jose (sync) 1000 604.42 op/sec │ ± 0.27 %+ 7.74 %
ES512 - fast-jwt (async with cache) │ 10000189999.48 op/sec │ ± 4.49 %+ 33767.60 %
RS256 - fast-jwt (async) │ 10007060.98 op/sec │ ± 0.38 % │ ║
RS256 - jsonwebtoken (async) │ 100016636.99 op/sec │ ± 0.50 %+ 135.62 %
RS256 - jsonwebtoken (sync) 100016915.78 op/sec │ ± 0.39 %+ 139.57 %
RS256 - jose (sync) 100017781.70 op/sec │ ± 0.85 %+ 151.83 %
RS256 - fast-jwt (sync) │ 100017884.95 op/sec │ ± 0.39 %+ 153.29 %
RS256 - fast-jwt (async with cache) │ 10000561798.73 op/sec │ ± 5.82 %+ 7856.39 %
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
ES512 - fast-jwt (sync with cache) │ 10000192353.61 op/sec │ ± 4.79 %+ 34187.22 %
RS256 - fast-jwt (sync with cache) │ 10000730630.87 op/sec │ ± 5.23 %+ 10247.44 %
╚═════════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝

╔═════════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
RS512 - jsonwebtoken (async) │ 1500 7551.10 op/sec │ ± 0.92 % │ ║
RS512 - jsonwebtoken (sync) 45007750.46 op/sec │ ± 0.96 %+ 2.64 %
RS512 - fast-jwt (async) 10008413.41 op/sec │ ± 0.99 %+ 11.42 %
RS512 - jose (sync) │ 450012382.58 op/sec │ ± 0.94 %+ 63.98 %
RS512 - fast-jwt (sync) │ 450012665.45 op/sec │ ± 0.90 %+ 67.73 %
RS512 - fast-jwt (sync with cache) 10000145107.65 op/sec │ ± 7.54 %+ 1821.68 %
HS512 - jsonwebtoken (async) │ 1000220177.36 op/sec │ ± 0.69 % │ ║
HS512 - fast-jwt (async) 1000221759.63 op/sec │ ± 0.47 %+ 0.72 %
HS512 - jsonwebtoken (sync) │ 10000239279.34 op/sec │ ± 1.26 %+ 8.68 %
HS512 - jose (sync) │ 10000270725.62 op/sec │ ± 1.69 %+ 22.96 %
HS512 - fast-jwt (sync) │ 10000321378.46 op/sec │ ± 1.96 %+ 45.96 %
HS512 - fast-jwt (async with cache) │ 10000661096.40 op/sec │ ± 9.09 %+ 200.26 %
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
RS512 - fast-jwt (async with cache) │ 10000158780.83 op/sec │ ± 3.90 %+ 2002.75 %
HS512 - fast-jwt (sync with cache) 10000781793.65 op/sec │ ± 5.63 %+ 255.07 %
╚═════════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝

╔═════════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
PS512 - jsonwebtoken (async) │ 25007240.21 op/sec │ ± 0.89 % │ ║
PS512 - jsonwebtoken (sync) 20007449.38 op/sec │ ± 0.91 %+ 2.89 %
PS512 - fast-jwt (async) │ 15008301.99 op/sec │ ± 0.81 %+ 14.67 %
PS512 - jose (sync) 400011944.57 op/sec │ ± 0.99 %+ 64.98 %
PS512 - fast-jwt (sync) │ 100012881.96 op/sec │ ± 0.76 %+ 77.92 %
PS512 - fast-jwt (async with cache) │ 10000155603.59 op/sec │ ± 4.27 %+ 2049.16 %
ES512 - fast-jwt (async) 1000 920.81 op/sec │ ± 0.09 % │ ║
ES512 - jsonwebtoken (async) │ 1000 944.60 op/sec │ ± 0.91 %+ 2.58 %
ES512 - jose (sync) 1000 977.66 op/sec │ ± 0.09 %+ 6.17 %
ES512 - jsonwebtoken (sync) 1000 980.18 op/sec │ ± 0.08 %+ 6.45 %
ES512 - fast-jwt (sync) │ 1000 983.04 op/sec │ ± 0.08 %+ 6.76 %
ES512 - fast-jwt (async with cache) │ 4000611845.04 op/sec │ ± 0.96 %+ 66346.49 %
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
PS512 - fast-jwt (sync with cache) │ 10000172097.91 op/sec │ ± 4.58 %+ 2276.97 %
ES512 - fast-jwt (sync with cache) │ 10000630467.45 op/sec │ ± 11.79 %+ 68368.89 %
╚═════════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝

╔═════════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ EdDSA - fast-jwt (async) │ 10006370.58 op/sec │ ± 0.59 % │ ║
║ EdDSA - jose (sync) │ 10006538.90 op/sec │ ± 0.83 %+ 2.64 %
║ EdDSA - fast-jwt (sync) │ 10007078.93 op/sec │ ± 0.87 %+ 11.12 %
║ EdDSA - fast-jwt (async with cache) │ 10000177457.09 op/sec │ ± 5.36 %+ 2685.57 %
RS512 - fast-jwt (async) │ 10006964.24 op/sec │ ± 0.19 % │ ║
RS512 - jsonwebtoken (async) │ 100015757.62 op/sec │ ± 0.59 %+ 126.26 %
RS512 - jsonwebtoken (sync) │ 100016967.83 op/sec │ ± 0.40 %+ 143.64 %
RS512 - fast-jwt (sync) │ 100017691.16 op/sec │ ± 0.20 %+ 154.03 %
RS512 - jose (sync) │ 100018512.16 op/sec │ ± 0.17 %+ 165.82 %
RS512 - fast-jwt (async with cache) │ 4000542514.19 op/sec │ ± 0.93 %+ 7689.99 %
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ EdDSA - fast-jwt (sync with cache) │ 10000202628.41 op/sec │ ± 3.12 %+ 3080.69 %
RS512 - fast-jwt (sync with cache) │ 10000551957.22 op/sec │ ± 8.69 %+ 7825.59 %
╚═════════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝

╔═════════════════════════════════════╤═════════╤═════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼─────────┼───────────┼─────────────────────────╢
PS512 - jsonwebtoken (async) │ 0 │ Errored │ N/AN/A
PS512 - jsonwebtoken (sync) │ 0 │ Errored │ N/AN/A
PS512 - jose (sync) │ 0 │ Errored │ N/AN/A
PS512 - fast-jwt (async with cache) │ 0 │ Errored │ N/AN/A
PS512 - fast-jwt (sync with cache) │ 0 │ Errored │ N/AN/A
PS512 - fast-jwt (async) │ 0 │ Errored │ N/AN/A
╟─────────────────────────────────────┼─────────┼─────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼─────────┼───────────┼─────────────────────────╢
PS512 - fast-jwt (sync) │ 0 │ Errored │ N/AN/A
╚═════════════════════════════════════╧═════════╧═════════╧═══════════╧═════════════════════════╝

╔═════════════════════════════════════╤═════════╤══════════════════╤═══════════╤═════════════════════════╗
║ Slower tests │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ EdDSA - fast-jwt (async) │ 10007788.29 op/sec │ ± 0.52 % │ ║
║ EdDSA - jose (sync) │ 100012210.20 op/sec │ ± 0.33 %+ 56.78 %
║ EdDSA - fast-jwt (sync) │ 100012262.06 op/sec │ ± 0.70 %+ 57.44 %
║ EdDSA - fast-jwt (async with cache) │ 4000611780.66 op/sec │ ± 0.97 %+ 7755.13 %
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ Fastest test │ Samples │ Result │ Tolerance │ Difference with slowest ║
╟─────────────────────────────────────┼─────────┼──────────────────┼───────────┼─────────────────────────╢
║ EdDSA - fast-jwt (sync with cache) │ 10000643679.66 op/sec │ ± 7.56 %+ 8164.71 %
╚═════════════════════════════════════╧═════════╧══════════════════╧═══════════╧═════════════════════════╝
```
30 changes: 23 additions & 7 deletions benchmarks/utils.mjs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

import nodeRsJwt, { Algorithm } from '@node-rs/jsonwebtoken'
import cronometro from 'cronometro'
import { createSecretKey } from 'crypto'
import { createSecretKey, createPublicKey, createPrivateKey } from 'crypto'
import { readFileSync } from 'fs'
import { mkdir, writeFile } from 'fs/promises'
import { dirname, resolve } from 'path'
@@ -132,14 +132,26 @@ export function compareDecoding(token, algorithm) {
)
}

function jsonwebtokenKeyFromString(publicKey) {
const jsonwebtokenBuffer = Buffer.from(publicKey)
function jsonwebtokenPrivateKeyFromString(privateKey) {
return jsonwebtokenKeyFromString(privateKey, createPrivateKey)
}

function jsonwebtokenSecretKeyFromString(publicKey) {
return jsonwebtokenKeyFromString(publicKey, createSecretKey)
}

function jsonwebtokenPublicKeyFromString(publicKey) {
return jsonwebtokenKeyFromString(publicKey, createPublicKey)
}

function jsonwebtokenKeyFromString(key, keyFunc) {
const jsonwebtokenBuffer = Buffer.from(key)
const jwtSecretDataview = new DataView(
jsonwebtokenBuffer.buffer,
jsonwebtokenBuffer.byteOffset,
jsonwebtokenBuffer.byteLength
)
return createSecretKey(jwtSecretDataview)
return keyFunc(jwtSecretDataview)
}

export async function compareSigning(payload, algorithm, privateKey, publicKey) {
@@ -150,7 +162,9 @@ export async function compareSigning(payload, algorithm, privateKey, publicKey)
const fastjwtVerify = createVerifier({ key: publicKey })

const josePrivateKey = asKey(privateKey)
const jsonwebtokenKey = jsonwebtokenKeyFromString(publicKey)
const jsonwebtokenKey = /^(?:RS|PS|ES)/.test(algorithm)
? jsonwebtokenPrivateKeyFromString(privateKey)
: jsonwebtokenSecretKeyFromString(publicKey)
const joseOptions = {
algorithm,
iat: false,
@@ -179,7 +193,7 @@ export async function compareSigning(payload, algorithm, privateKey, publicKey)
log(`@node-rs/jsonwebtoken: ${JSON.stringify(nodeRsGenerated)}`)
log('Generated tokens verification:')
if (!isEdDSA) {
log(` jsonwebtoken: ${JSON.stringify(jsonwebtokenVerify(jsonwebtokenGenerated, jsonwebtokenKey))}`)
log(` jsonwebtoken: ${JSON.stringify(jsonwebtokenVerify(jsonwebtokenGenerated, asKey(publicKey)))}`)
}
log(` jose: ${JSON.stringify(joseVerify(joseGenerated, asKey(publicKey)))}`)
log(` fastjwt: ${JSON.stringify(fastjwtVerify(fastjwtGenerated))}`)
@@ -236,7 +250,9 @@ export function compareVerifying(token, algorithm, publicKey) {
const fastjwtCachedVerifyAsync = createVerifier({ key: async () => publicKey, cache: true })

const josePublicKey = asKey(publicKey)
const jsonwebtokenKey = jsonwebtokenKeyFromString(publicKey)
const jsonwebtokenKey = /^(?:RS|PS|ES)/.test(algorithm)
? jsonwebtokenPublicKeyFromString(publicKey)
: jsonwebtokenSecretKeyFromString(publicKey)

if ((process.env.NODE_DEBUG || '').includes('fast-jwt')) {
log('-------')

0 comments on commit 9c05fa5

Please sign in to comment.