pbkdf2 iter count

Benchmark created on


Setup

function b64(a) {
  return btoa(String.fromCodePoint.apply(null, Array.from(a)));
}

async function hash(s, i) {
    const st = crypto.getRandomValues(new Uint8Array(16));
    const hh = await hash2(s, st, i);
    return b64(st) + b64(hh);
}

async function hash2(s, salt, iterations) {
  const a = new TextEncoder().encode(s);
  const kk = await crypto.subtle.importKey(
    "raw", a, "PBKDF2", false, ["deriveBits"],
  );

  const b = await crypto.subtle.deriveBits(
    { name: "PBKDF2", hash: "SHA-256", salt, iterations },
    kk,
    256,
  );
  return new Uint8Array(b);
}

Test runner

Ready to run.

Testing in
TestOps/sec
1e5
hash("abcdefghijklmn", 1e5).then(x => deferred.resolve(x))
ready
5e5
hash("abcdefghijklmn", 5e5).then(x => deferred.resolve(x))
ready
1e6
hash("abcdefghijklmn", 1e6).then(x => deferred.resolve(x))
ready
5e6
hash("abcdefghijklmn", 5e6).then(x => deferred.resolve(x))
ready
1e7
hash("abcdefghijklmn", 1e7).then(x => deferred.resolve(x))
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.