This benchmark compares various configurations of crypto.createHash
from
Node.js core with crypto_generichash
.
The winner is:
const { crypto_generichash } = require('sodium-universal/crypto_generichash')
const output = Buffer.alloc(64)
// Note! This reuses the same Buffer over and over again. You only own it until
// the next call. You can either copy it (the no prealloc test does this) or
// you can turn it into whatever string format you require
// (the prealloc, digest does this). Note that these two suggestions of course
// change the performance, so review the numbers in the tables below
function hash (data) {
crypto_generichash(output, data)
return output
}
uname: Linux 4.15.0-38-generic #41-Ubuntu SMP Wed Oct 10 10:59:38 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Model: Hetzner EX41-SSD
CPU: Intel Core i7-6700 Quad Core
Memory: 32 GB DDR4
Disk: 2Γ 500 GB SSD
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ββββββββββ€ββββββββββββββββββββ€ββββββββββββ€ββββββββββββββββββββββββββ
β Slower tests β Samples β Result β Tolerance β Difference with slowest β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β crypto sha256 (prealloc) β 10000 β 370321.25 op/sec β Β± 4.65 % β β
β crypto sha512 (prealloc) β 1000 β 382075.76 op/sec β Β± 0.94 % β + 3.17 % β
β crypto blake2b512 (prealloc) β 1000 β 401530.47 op/sec β Β± 0.98 % β + 8.43 % β
β crypto sha256 (no prealloc) β 1000 β 453419.74 op/sec β Β± 0.80 % β + 22.44 % β
β crypto sha512 (no prealloc) β 1000 β 460150.51 op/sec β Β± 0.69 % β + 24.26 % β
β crypto blake2b512 (no prealloc) β 1000 β 478510.57 op/sec β Β± 0.96 % β + 29.21 % β
β crypto sha256 (no prealloc, digest) β 10000 β 566184.79 op/sec β Β± 9.17 % β + 52.89 % β
β crypto sha512 (no prealloc, digest) β 1500 β 572655.25 op/sec β Β± 0.93 % β + 54.64 % β
β sodium-native generichash (state no reuse, digest) β 10000 β 608201.51 op/sec β Β± 8.16 % β + 64.24 % β
β crypto blake2b512 (no prealloc, digest) β 1500 β 635363.84 op/sec β Β± 0.79 % β + 71.57 % β
β sodium-native generichash (32, state no reuse, digest) β 1500 β 693007.10 op/sec β Β± 0.84 % β + 87.14 % β
β sodium-native generichash (state no reuse) β 10000 β 726852.47 op/sec β Β± 9.45 % β + 96.28 % β
β sodium-native generichash (32, state no reuse) β 1500 β 780502.02 op/sec β Β± 0.97 % β + 110.76 % β
β sodium-native generichash (32, no prealloc, digest) β 10000 β 880695.68 op/sec β Β± 12.49 % β + 137.82 % β
β sodium-native generichash (no prealloc, digest) β 10000 β 920298.64 op/sec β Β± 11.46 % β + 148.51 % β
β sodium-native generichash (state reuse, digest) β 10000 β 995537.40 op/sec β Β± 11.67 % β + 168.83 % β
β sodium-native generichash (32, state reuse, digest) β 10000 β 1091170.46 op/sec β Β± 12.17 % β + 194.66 % β
β sodium-native generichash (32, no prealloc) β 10000 β 1279935.12 op/sec β Β± 13.74 % β + 245.63 % β
β sodium-native generichash (no prealloc) β 10000 β 1284029.51 op/sec β Β± 14.66 % β + 246.73 % β
β sodium-native generichash (prealloc, digest) β 1500 β 1326325.62 op/sec β Β± 0.99 % β + 258.16 % β
β sodium-native generichash (state reuse) β 10000 β 1336378.49 op/sec β Β± 15.10 % β + 260.87 % β
β sodium-native generichash (32, state reuse) β 10000 β 1339021.68 op/sec β Β± 15.02 % β + 261.58 % β
β sodium-native generichash (32, prealloc, digest) β 10000 β 1368295.10 op/sec β Β± 15.15 % β + 269.49 % β
β sodium-native generichash (32, prealloc) β 10000 β 1728572.91 op/sec β Β± 19.03 % β + 366.78 % β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β Fastest test β Samples β Result β Tolerance β Difference with slowest β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β sodium-native generichash (prealloc) β 10000 β 1753616.83 op/sec β Β± 18.99 % β + 373.54 % β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ§ββββββββββ§ββββββββββββββββββββ§ββββββββββββ§ββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ββββββββββ€ββββββββββββββββββββ€ββββββββββββ€ββββββββββββββββββββββββββ
β Slower tests β Samples β Result β Tolerance β Difference with slowest β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β crypto blake2b512 (prealloc) β 10000 β 372311.59 op/sec β Β± 6.84 % β β
β crypto sha256 (prealloc) β 1500 β 374951.26 op/sec β Β± 0.80 % β + 0.71 % β
β crypto sha512 (prealloc) β 1000 β 384112.49 op/sec β Β± 1.00 % β + 3.17 % β
β crypto sha256 (no prealloc) β 1500 β 454828.00 op/sec β Β± 0.77 % β + 22.16 % β
β crypto sha512 (no prealloc) β 10000 β 455139.02 op/sec β Β± 5.29 % β + 22.25 % β
β crypto blake2b512 (no prealloc) β 1500 β 478152.72 op/sec β Β± 0.77 % β + 28.43 % β
β crypto sha512 (no prealloc, digest) β 1500 β 479625.05 op/sec β Β± 0.84 % β + 28.82 % β
β crypto sha256 (no prealloc, digest) β 10000 β 528125.65 op/sec β Β± 8.39 % β + 41.85 % β
β sodium-native generichash (state no reuse, digest) β 10000 β 611080.95 op/sec β Β± 7.86 % β + 64.13 % β
β sodium-native generichash (32, state no reuse, digest) β 10000 β 618889.17 op/sec β Β± 8.50 % β + 66.23 % β
β crypto blake2b512 (no prealloc, digest) β 1500 β 634007.66 op/sec β Β± 0.84 % β + 70.29 % β
β sodium-native generichash (state no reuse) β 10000 β 696540.21 op/sec β Β± 9.83 % β + 87.09 % β
β sodium-native generichash (32, state no reuse) β 10000 β 733222.33 op/sec β Β± 9.02 % β + 96.94 % β
β sodium-native generichash (32, no prealloc, digest) β 10000 β 883429.92 op/sec β Β± 11.88 % β + 137.28 % β
β sodium-native generichash (no prealloc, digest) β 10000 β 966337.35 op/sec β Β± 11.34 % β + 159.55 % β
β sodium-native generichash (state reuse, digest) β 1500 β 1085023.14 op/sec β Β± 0.77 % β + 191.43 % β
β sodium-native generichash (32, state reuse, digest) β 1500 β 1129635.46 op/sec β Β± 0.85 % β + 203.41 % β
β sodium-native generichash (no prealloc) β 10000 β 1200031.58 op/sec β Β± 14.04 % β + 222.32 % β
β sodium-native generichash (32, no prealloc) β 1500 β 1278665.55 op/sec β Β± 0.97 % β + 243.44 % β
β sodium-native generichash (prealloc, digest) β 10000 β 1301504.94 op/sec β Β± 14.47 % β + 249.57 % β
β sodium-native generichash (32, prealloc, digest) β 10000 β 1328428.24 op/sec β Β± 14.66 % β + 256.81 % β
β sodium-native generichash (32, state reuse) β 10000 β 1329011.92 op/sec β Β± 14.92 % β + 256.96 % β
β sodium-native generichash (state reuse) β 10000 β 1343705.12 op/sec β Β± 15.05 % β + 260.91 % β
β sodium-native generichash (32, prealloc) β 10000 β 1684187.27 op/sec β Β± 19.43 % β + 352.36 % β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β Fastest test β Samples β Result β Tolerance β Difference with slowest β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β sodium-native generichash (prealloc) β 10000 β 1738361.93 op/sec β Β± 19.31 % β + 366.91 % β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ§ββββββββββ§ββββββββββββββββββββ§ββββββββββββ§ββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ββββββββββ€ββββββββββββββββββββ€ββββββββββββ€ββββββββββββββββββββββββββ
β Slower tests β Samples β Result β Tolerance β Difference with slowest β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β crypto sha512 (no prealloc) β 10000 β 369661.84 op/sec β Β± 9.98 % β β
β crypto sha512 (prealloc) β 1000 β 380689.89 op/sec β Β± 0.99 % β + 2.98 % β
β crypto blake2b512 (prealloc) β 10000 β 382871.26 op/sec β Β± 6.72 % β + 3.57 % β
β crypto sha256 (prealloc) β 1000 β 386591.76 op/sec β Β± 1.00 % β + 4.58 % β
β crypto sha256 (no prealloc) β 1500 β 443099.52 op/sec β Β± 0.85 % β + 19.87 % β
β crypto blake2b512 (no prealloc) β 10000 β 457414.73 op/sec β Β± 7.44 % β + 23.74 % β
β crypto sha256 (no prealloc, digest) β 10000 β 548032.35 op/sec β Β± 9.94 % β + 48.25 % β
β crypto sha512 (no prealloc, digest) β 1500 β 570256.56 op/sec β Β± 0.81 % β + 54.26 % β
β crypto blake2b512 (no prealloc, digest) β 10000 β 575250.97 op/sec β Β± 9.29 % β + 55.62 % β
β sodium-native generichash (state no reuse, digest) β 10000 β 611746.59 op/sec β Β± 8.01 % β + 65.49 % β
β sodium-native generichash (32, state no reuse, digest) β 10000 β 639786.14 op/sec β Β± 7.20 % β + 73.07 % β
β sodium-native generichash (state no reuse) β 10000 β 677225.74 op/sec β Β± 9.68 % β + 83.20 % β
β sodium-native generichash (32, state no reuse) β 10000 β 689778.67 op/sec β Β± 10.06 % β + 86.60 % β
β sodium-native generichash (no prealloc, digest) β 10000 β 951090.19 op/sec β Β± 11.43 % β + 157.29 % β
β sodium-native generichash (state reuse, digest) β 10000 β 963677.73 op/sec β Β± 11.96 % β + 160.69 % β
β sodium-native generichash (32, no prealloc, digest) β 10000 β 1006172.77 op/sec β Β± 11.48 % β + 172.19 % β
β sodium-native generichash (32, state reuse, digest) β 1500 β 1141885.34 op/sec β Β± 0.93 % β + 208.90 % β
β sodium-native generichash (32, no prealloc) β 10000 β 1224765.39 op/sec β Β± 15.21 % β + 231.32 % β
β sodium-native generichash (no prealloc) β 1500 β 1295408.38 op/sec β Β± 0.96 % β + 250.43 % β
β sodium-native generichash (prealloc, digest) β 1500 β 1298480.95 op/sec β Β± 0.91 % β + 251.26 % β
β sodium-native generichash (state reuse) β 10000 β 1344304.29 op/sec β Β± 15.27 % β + 263.66 % β
β sodium-native generichash (32, state reuse) β 10000 β 1416489.18 op/sec β Β± 15.57 % β + 283.19 % β
β sodium-native generichash (32, prealloc, digest) β 1500 β 1422591.13 op/sec β Β± 0.97 % β + 284.84 % β
β sodium-native generichash (32, prealloc) β 10000 β 1719170.71 op/sec β Β± 18.64 % β + 365.07 % β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β Fastest test β Samples β Result β Tolerance β Difference with slowest β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β sodium-native generichash (prealloc) β 10000 β 1838778.14 op/sec β Β± 19.96 % β + 397.42 % β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ§ββββββββββ§ββββββββββββββββββββ§ββββββββββββ§ββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ββββββββββ€ββββββββββββββββββββ€ββββββββββββ€ββββββββββββββββββββββββββ
β Slower tests β Samples β Result β Tolerance β Difference with slowest β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β crypto sha512 (prealloc) β 1500 β 376676.21 op/sec β Β± 0.89 % β β
β crypto sha256 (prealloc) β 1500 β 380066.77 op/sec β Β± 0.83 % β + 0.90 % β
β crypto blake2b512 (prealloc) β 1000 β 404266.63 op/sec β Β± 0.99 % β + 7.32 % β
β crypto sha512 (no prealloc) β 1500 β 414760.15 op/sec β Β± 0.88 % β + 10.11 % β
β crypto sha256 (no prealloc) β 10000 β 415093.26 op/sec β Β± 6.46 % β + 10.20 % β
β crypto blake2b512 (no prealloc) β 1500 β 480911.04 op/sec β Β± 0.81 % β + 27.67 % β
β crypto sha256 (no prealloc, digest) β 1500 β 607580.42 op/sec β Β± 0.83 % β + 61.30 % β
β crypto sha512 (no prealloc, digest) β 1500 β 615386.89 op/sec β Β± 0.77 % β + 63.37 % β
β crypto blake2b512 (no prealloc, digest) β 1500 β 631145.25 op/sec β Β± 0.80 % β + 67.56 % β
β sodium-native generichash (state no reuse, digest) β 10000 β 658077.79 op/sec β Β± 7.58 % β + 74.71 % β
β sodium-native generichash (32, state no reuse) β 10000 β 675431.84 op/sec β Β± 9.73 % β + 79.31 % β
β sodium-native generichash (32, state no reuse, digest) β 10000 β 679460.08 op/sec β Β± 7.46 % β + 80.38 % β
β sodium-native generichash (state no reuse) β 10000 β 705066.12 op/sec β Β± 9.27 % β + 87.18 % β
β sodium-native generichash (no prealloc, digest) β 10000 β 922448.55 op/sec β Β± 10.81 % β + 144.89 % β
β sodium-native generichash (32, no prealloc, digest) β 10000 β 964307.23 op/sec β Β± 11.74 % β + 156.00 % β
β sodium-native generichash (state reuse, digest) β 10000 β 1062845.19 op/sec β Β± 11.89 % β + 182.16 % β
β sodium-native generichash (32, state reuse, digest) β 10000 β 1102679.90 op/sec β Β± 12.22 % β + 192.74 % β
β sodium-native generichash (no prealloc) β 10000 β 1105141.51 op/sec β Β± 14.53 % β + 193.39 % β
β sodium-native generichash (prealloc, digest) β 10000 β 1211828.61 op/sec β Β± 13.80 % β + 221.72 % β
β sodium-native generichash (32, no prealloc) β 10000 β 1324412.97 op/sec β Β± 14.42 % β + 251.61 % β
β sodium-native generichash (state reuse) β 10000 β 1364409.49 op/sec β Β± 15.10 % β + 262.22 % β
β sodium-native generichash (32, state reuse) β 10000 β 1370257.76 op/sec β Β± 14.99 % β + 263.78 % β
β sodium-native generichash (32, prealloc, digest) β 1500 β 1398581.84 op/sec β Β± 0.97 % β + 271.30 % β
β sodium-native generichash (prealloc) β 10000 β 1638734.17 op/sec β Β± 18.44 % β + 335.05 % β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β Fastest test β Samples β Result β Tolerance β Difference with slowest β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββΌββββββββββΌββββββββββββββββββββΌββββββββββββΌββββββββββββββββββββββββββ’
β sodium-native generichash (32, prealloc) β 10000 β 1706066.86 op/sec β Β± 20.97 % β + 352.93 % β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ§ββββββββββ§ββββββββββββββββββββ§ββββββββββββ§ββββββββββββββββββββββββββ