Skip to content

Commit

Permalink
Add benchmark for Argon2
Browse files Browse the repository at this point in the history
  • Loading branch information
ranisalt committed Oct 29, 2023
1 parent 2e6a3e5 commit f2e66e2
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions benchmark/crypto/argon2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict';

const common = require('../common.js');
const assert = require('node:assert');
const {
argon2,
argon2Sync,
} = require('node:crypto');

const bench = common.createBenchmark(main, {
sync: [0, 1],
size: [32, 64, 1024],
pass: ['a', 'secret', 'this-is-a-much-longer-password'],
saltlen: [8, 16, 32],
algorithm: ['ARGON2D', 'ARGON2I', 'ARGON2ID'],
secretlen: [0, 8],
adlen: [0, 12],
iter: [2, 3, 4],
memcost: [64 << 10, 256 << 10],
n: [50],
});

function measureSync(n, size, pass, salt, options) {
bench.start();
for (let i = 0; i < n; ++i)
argon2Sync(pass, salt, size, options);
bench.end(n);
}

function measureAsync(n, size, pass, salt, options) {
let remaining = n;
function done(err) {
assert.ifError(err);
if (--remaining === 0)
bench.end(n);
}
bench.start();
for (let i = 0; i < n; ++i)
argon2(pass, salt, size, options, done);
}

function main({ n, sync, size, pass, saltlen, secretlen, adlen, ...options }) {
const salt = Buffer.alloc(saltlen, 0x01);
const secret = Buffer.alloc(secretlen, 0x02);
const ad = Buffer.alloc(adlen, 0x03);
options = { ...options, secret, ad };
if (sync)
measureSync(n, size, pass, salt, options);
else
measureAsync(n, size, pass, salt, options);
}

0 comments on commit f2e66e2

Please sign in to comment.