Skip to content

Commit

Permalink
test: organize benchmarks better and add test against other libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
oplik0 committed Apr 11, 2024
1 parent 7bb08c0 commit 4061d69
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 123 deletions.
83 changes: 81 additions & 2 deletions deno.lock

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

242 changes: 121 additions & 121 deletions lib/scrypt_bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,140 +4,140 @@
*/
import { scrypt as scryptOld } from "https://deno.land/x/[email protected]/lib/scrypt.ts";
import { scrypt } from "./scrypt.ts";
import { scrypt as scryptNodeRaw } from "node:crypto";
import { scrypt as scryptoRaw } from "https://deno.land/x/[email protected]/main.ts";
import { scrypt as scryptWasmRaw } from "npm:hash-wasm"

function scryptNode(
password: string,
salt: string,
N: number,
r: number,
p: number,
dklen: number = 64,
) {
return new Promise((resolve) =>
scryptNodeRaw(password, salt, dklen, { N, r, p }, resolve)
);
}

function scrypto(
password: string,
salt: string,
N: number,
r: number,
p: number,
dkLen: number = 64,
) {
return scryptoRaw(password, salt, { N, r, p, dkLen})
}

function scryptWasm (
password: string,
salt: string,
N: number,
r: number,
p: number,
dkLen: number = 64,
) {
return scryptWasmRaw({password, salt, costFactor: N, blockSize: r, parallelism: p, hashLength: dkLen});
}

const scryptImplementations = {
"current": scrypt,
"last version": scryptOld,
"node": scryptNode,
"scrypto": scrypto,
"hash-wasm": scryptWasm,
};

const extremeSalt =
`IkjpewCbNm4A7cuY1VL9KC3y92blEthtLf9Cet6uEoTxz5cyF660da2zeci42fYwVCVwsKogETMCXupSZZAUh6a80ZnnBTk17B3UTCSVQPpYfL8GktJ2BDokE7ox2hV8OwwUT1hFvCuJqwHZpRvZw1RNCO6HfukPdgMHhq9rWLTXXUNwrIjlmkeydKGFJz2mS1xFcvLQtle4olJVK0SXXXYHAigBfpYxxSC2acvoxuacWcXhzSSRZAMysU2J7zDfXdxnYoqz50rvmvi36g7t2WDSAd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Reep2qUVaqJn8onzsI6da6pU6iDtRbufWxi0q8XN1S3BCtFGjzaTU12nvfg5js53PiSw1KUnZj2thKxWtnKcpwzbXdTuuZ9GVhZHIMcOXXrDR0rj539ZLAVyJmqwDOMjTsqPN7BY522PcJHoTElSRNRAsAsFx2m7h9brhcZXOgV1PZohJsdQS7RWhAl9EYBkgF8WCgGw9DXidVduIIHDlEd7mAVJfo9HYX85kFcwrLEpuPiFxfNhubeDpeBu2FAbAo6DNHFlqXUUnyKvMbzptcgisSr2V1pwykB6uLVrwx3AceRnyqg5flldmfsSKw0AFZ4PagGMJuFDMGrV29Vmqhv61SRL9in0ngZx0gJ2vKv26qS3jGN72UUsbkysuGNz6ul0D5jIapvIcCTncIiXSY24pPctxFsawcXvSNw4jEKccsHCTZF0gri6iFS7JqqQd87FNowbrug6sIWSwiWHYGN1VfSwuE5plQHVvNCHNZnMBBIoaMWh45lhtlfCWdUwVpjjK5dAUcOtKftJ2hcl4mIlxs7Fy8ASWhYvWAbpp3fRgmAeTRYAFEwMohN9b03iXyDSNFIeZtQoaL7HYFVWoXV4BfBVlR3CvNIwp6OPBAFFSDlSn9CZU06UziY1tSwqBzkCD`;

Deno.bench("small scrypt - last version", { group: "small scrypt" }, () => {
scryptOld("password", "salt", 1024, 8, 1, 64);
});
Deno.bench("small scrypt", { group: "small scrypt", baseline: true }, () => {
scrypt("password", "salt", 1024, 8, 1, 64);
});

Deno.bench("small scrypt - last version (longer password and salt)", {
group: "small scrypt (longer password and salt)",
}, () => {
scryptOld(
"long password to test that",
"long salt to test that",
1024,
8,
1,
64,
);
});
Deno.bench("small scrypt (longer password and salt)", {
group: "small scrypt (longer password and salt)",
baseline: true,
}, () => {
scrypt(
"long password to test that",
"long salt to test that",
1024,
8,
1,
64,
);
});

Deno.bench("small scrypt - last version (extremely long password and salt)", {
group: "small scrypt (extremely long password and salt)",
}, () => {
scryptOld(extremePassword, extremeSalt, 1024, 8, 1, 64);
});
Deno.bench("small scrypt (extremely long password and salt)", {
group: "small scrypt (extremely long password and salt)",
baseline: true,
}, () => {
scrypt(extremePassword, extremeSalt, 1024, 8, 1, 64);
});

Deno.bench("standard scrypt - last version", { group: "scrypt" }, () => {
scryptOld("password", "salt", 16384, 8, 1, 64);
});
Deno.bench("standard scrypt", { group: "scrypt", baseline: true }, () => {
scrypt("password", "salt", 16384, 8, 1, 64);
});
for (const [name, implementation] of Object.entries(scryptImplementations)) {
Deno.bench(`small scrypt - ${name}`, {
group: "small scrypt",
baseline: name === "current",
}, async () => {
await implementation("password", "salt", 1024, 8, 1, 64);
});

Deno.bench(
"standard scrypt - last version (longer password and salt)",
{ group: "scrypt (longer password and salt)" },
() => {
scryptOld(
Deno.bench(`small scrypt - ${name} (longer password and salt)`, {
group: "small scrypt (longer password and salt)",
baseline: name === "current",
}, async () => {
await implementation(
"long password to test that",
"long salt to test that",
16384,
1024,
8,
1,
64,
);
},
);
Deno.bench(
"standard scrypt (longer password and salt)",
{ group: "scrypt (longer password and salt)", baseline: true },
() => {
scrypt(
"long password to test that",
"long salt to test that",
16384,
8,
1,
64,
);
},
);
});

Deno.bench(`small scrypt - ${name} (extremely long password and salt)`, {
group: "small scrypt (extremely long password and salt)",
baseline: name === "current",
}, async () => {
await implementation(extremePassword, extremeSalt, 1024, 8, 1, 64);
});

Deno.bench(
"standard scrypt - last version (extremely long password and salt)",
{
group: "scrypt (extremely long password and salt)",
},
() => {
scryptOld(extremePassword, extremeSalt, 16384, 8, 1, 64);
},
);
Deno.bench("standard scrypt (extremely long password and salt)", {
group: "scrypt (extremely long password and salt)",
baseline: true,
}, () => {
scrypt(extremePassword, extremeSalt, 16384, 8, 1, 64);
});
Deno.bench(`standard scrypt - ${name}`, {
group: "scrypt",
baseline: name === "current",
}, async () => {
await implementation("password", "salt", 16384, 8, 1, 64);
});
Deno.bench(
`standard scrypt - ${name} (longer password and salt)`,
{
group: "scrypt (longer password and salt)",
baseline: name === "current",
},
async () => {
await implementation(
"long password to test that",
"long salt to test that",
16384,
8,
1,
64,
);
},
);

Deno.bench(
`standard scrypt - ${name} (extremely long password and salt)`,
{
group: "scrypt (extremely long password and salt)",
baseline: name === "current",
},
async () => {
await implementation(extremePassword, extremeSalt, 16384, 8, 1, 64);
},
);

Deno.bench("large n scrypt - last version (4x standard)", {
group: "large n scrypt",
}, () => {
scryptOld("password", "salt", 65536, 8, 1, 64);
});
Deno.bench("large n scrypt (4x standard)", {
group: "large n scrypt",
baseline: true,
}, () => {
scrypt("password", "salt", 65536, 8, 1, 64);
});
Deno.bench(`large n scrypt - ${name} (4x standard)`, {
group: "large n scrypt",
baseline: name === "current",
}, async () => {
await implementation("password", "salt", 65536, 8, 1, 64);
});

Deno.bench("large r scrypt - last version (4x standard)", {
group: "large r scrypt",
}, () => {
scryptOld("password", "salt", 16384, 32, 1, 64);
});
Deno.bench("large r scrypt (4x standard)", {
group: "large r scrypt",
baseline: true,
}, () => {
scrypt("password", "salt", 16384, 32, 1, 64);
});
Deno.bench(`large r scrypt - ${name} (4x standard)`, {
group: "large r scrypt",
baseline: name === "current",
}, async () => {
await implementation("password", "salt", 16384, 32, 1, 64);
});

Deno.bench("large p scrypt - last version (4x standard)", {
group: "large p scrypt",
}, () => {
scryptOld("password", "salt", 16384, 8, 4, 64);
});
Deno.bench("large p scrypt (4x standard)", {
group: "large p scrypt",
baseline: true,
}, () => {
scrypt("password", "salt", 16384, 8, 4, 64);
});
Deno.bench(`large p scrypt - ${name} (4x standard)`, {
group: "large p scrypt",
baseline: name === "current",
}, async () => {
await implementation("password", "salt", 16384, 8, 4, 64);
});
}

0 comments on commit 4061d69

Please sign in to comment.