@sebastienrousseau/crypto-benchmarks 0.0.34 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/benchmarks/pqc.js +1 -1
- package/dist/benchmarks/streaming.js +4 -4
- package/dist/timer.d.ts.map +1 -1
- package/dist/timer.js +38 -31
- package/package.json +3 -2
package/dist/benchmarks/pqc.js
CHANGED
|
@@ -14,7 +14,7 @@ function createPqcOperations() {
|
|
|
14
14
|
const message = node_crypto_1.default.randomBytes(32);
|
|
15
15
|
const { signature } = (0, crypto_lib_1.mlDsaSign)(65, dsa.secretKey, message);
|
|
16
16
|
return {
|
|
17
|
-
mlKem768Encapsulate: () => (0, crypto_lib_1.
|
|
17
|
+
mlKem768Encapsulate: () => (0, crypto_lib_1.mlKemEncapsulate)(768, kem.publicKey),
|
|
18
18
|
mlKem768SecretKey: kem.secretKey,
|
|
19
19
|
mlDsa65Verify: () => (0, crypto_lib_1.mlDsaVerify)(65, dsa.publicKey, message, signature),
|
|
20
20
|
};
|
|
@@ -9,11 +9,11 @@ const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
|
9
9
|
const crypto_lib_1 = require("@sebastienrousseau/crypto-lib");
|
|
10
10
|
const timer_1 = require("../timer");
|
|
11
11
|
function createMultiRecipients() {
|
|
12
|
-
const aliceX = (0, crypto_lib_1.
|
|
12
|
+
const aliceX = (0, crypto_lib_1.x25519Keygen)();
|
|
13
13
|
const aliceMl = (0, crypto_lib_1.mlKemKeygen)(768);
|
|
14
|
-
const bobX = (0, crypto_lib_1.
|
|
14
|
+
const bobX = (0, crypto_lib_1.x25519Keygen)();
|
|
15
15
|
const bobMl = (0, crypto_lib_1.mlKemKeygen)(768);
|
|
16
|
-
const charlieX = (0, crypto_lib_1.
|
|
16
|
+
const charlieX = (0, crypto_lib_1.x25519Keygen)();
|
|
17
17
|
const charlieMl = (0, crypto_lib_1.mlKemKeygen)(768);
|
|
18
18
|
const recipients = [
|
|
19
19
|
{
|
|
@@ -45,7 +45,7 @@ function createStreamingOperations() {
|
|
|
45
45
|
const payload64k = node_crypto_1.default.randomBytes(64 * 1024);
|
|
46
46
|
const symmetricKey = node_crypto_1.default.randomBytes(32);
|
|
47
47
|
const symEnc = (0, crypto_lib_1.streamEncrypt)({ key: symmetricKey, plaintext: payload64k });
|
|
48
|
-
const x25519 = (0, crypto_lib_1.
|
|
48
|
+
const x25519 = (0, crypto_lib_1.x25519Keygen)();
|
|
49
49
|
const mlkem = (0, crypto_lib_1.mlKemKeygen)(768);
|
|
50
50
|
const pqEnc = (0, crypto_lib_1.streamPqEncrypt)({
|
|
51
51
|
recipientX25519Public: x25519.publicKey,
|
package/dist/timer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;
|
|
1
|
+
{"version":3,"file":"timer.d.ts","sourceRoot":"","sources":["../src/timer.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAgFD,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC9B,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,cAAc,CAAC,CAUzB"}
|
package/dist/timer.js
CHANGED
|
@@ -11,47 +11,54 @@ async function runOnce(fn) {
|
|
|
11
11
|
await res;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const toMs = (ns) => Number(ns) / 1_000_000;
|
|
15
|
+
const round4 = (ms) => Number(ms.toFixed(4));
|
|
16
|
+
function resolveOptions(options) {
|
|
17
|
+
const { iterations, warmup } = options;
|
|
18
|
+
return {
|
|
19
|
+
iterations: iterations && iterations > 0 ? iterations : 10,
|
|
20
|
+
warmup: warmup !== undefined && warmup >= 0 ? warmup : 2,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
async function sample(fn, iterations) {
|
|
20
24
|
const timesMs = [];
|
|
21
25
|
const startTotal = node_process_1.default.hrtime.bigint();
|
|
22
26
|
for (let i = 0; i < iterations; i++) {
|
|
23
27
|
const start = node_process_1.default.hrtime.bigint();
|
|
24
28
|
await runOnce(fn);
|
|
25
|
-
|
|
26
|
-
const diffMs = Number(end - start) / 1_000_000;
|
|
27
|
-
timesMs.push(diffMs);
|
|
29
|
+
timesMs.push(toMs(node_process_1.default.hrtime.bigint() - start));
|
|
28
30
|
}
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
+
const totalDurationMs = toMs(node_process_1.default.hrtime.bigint() - startTotal);
|
|
32
|
+
return { timesMs, totalDurationMs };
|
|
33
|
+
}
|
|
34
|
+
const percentile = (sorted, q) => sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * q))];
|
|
35
|
+
function median(sorted) {
|
|
36
|
+
const mid = Math.floor(sorted.length / 2);
|
|
37
|
+
return sorted.length % 2 !== 0
|
|
38
|
+
? sorted[mid]
|
|
39
|
+
: (sorted[mid - 1] + sorted[mid]) / 2;
|
|
40
|
+
}
|
|
41
|
+
function summarize(timesMs, iterations, totalDurationMs) {
|
|
31
42
|
timesMs.sort((a, b) => a - b);
|
|
32
|
-
const minMs = timesMs[0];
|
|
33
|
-
const maxMs = timesMs[timesMs.length - 1];
|
|
34
43
|
const sumMs = timesMs.reduce((acc, val) => acc + val, 0);
|
|
35
|
-
const meanMs = sumMs / iterations;
|
|
36
|
-
const mid = Math.floor(timesMs.length / 2);
|
|
37
|
-
const medianMs = timesMs.length % 2 !== 0
|
|
38
|
-
? timesMs[mid]
|
|
39
|
-
: (timesMs[mid - 1] + timesMs[mid]) / 2;
|
|
40
|
-
const p95Idx = Math.min(timesMs.length - 1, Math.floor(timesMs.length * 0.95));
|
|
41
|
-
const p99Idx = Math.min(timesMs.length - 1, Math.floor(timesMs.length * 0.99));
|
|
42
|
-
const p95Ms = timesMs[p95Idx];
|
|
43
|
-
const p99Ms = timesMs[p99Idx];
|
|
44
|
-
const opsPerSec = (iterations / totalDurationMs) * 1000;
|
|
45
44
|
return {
|
|
46
|
-
meanMs:
|
|
47
|
-
medianMs:
|
|
48
|
-
minMs:
|
|
49
|
-
maxMs:
|
|
50
|
-
p95Ms:
|
|
51
|
-
p99Ms:
|
|
52
|
-
opsPerSec: Math.round(
|
|
53
|
-
totalDurationMs:
|
|
45
|
+
meanMs: round4(sumMs / iterations),
|
|
46
|
+
medianMs: round4(median(timesMs)),
|
|
47
|
+
minMs: round4(timesMs[0]),
|
|
48
|
+
maxMs: round4(timesMs[timesMs.length - 1]),
|
|
49
|
+
p95Ms: round4(percentile(timesMs, 0.95)),
|
|
50
|
+
p99Ms: round4(percentile(timesMs, 0.99)),
|
|
51
|
+
opsPerSec: Math.round((iterations / totalDurationMs) * 1000),
|
|
52
|
+
totalDurationMs: round4(totalDurationMs),
|
|
54
53
|
iterations,
|
|
55
54
|
};
|
|
56
55
|
}
|
|
56
|
+
async function benchmarkOperation(fn, options = {}) {
|
|
57
|
+
const { iterations, warmup } = resolveOptions(options);
|
|
58
|
+
for (let i = 0; i < warmup; i++) {
|
|
59
|
+
await runOnce(fn);
|
|
60
|
+
}
|
|
61
|
+
const { timesMs, totalDurationMs } = await sample(fn, iterations);
|
|
62
|
+
return summarize(timesMs, iterations, totalDurationMs);
|
|
63
|
+
}
|
|
57
64
|
//# sourceMappingURL=timer.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebastienrousseau/crypto-benchmarks",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.36",
|
|
4
4
|
"description": "Benchmarks comparing classical and post-quantum cryptography in JavaScript: ops/sec, latency and throughput for RSA, ECDSA, AES, SHA-2, ML-KEM and ML-DSA.",
|
|
5
5
|
"author": "Sebastien Rousseau <sebastienrousseau@users.noreply.github.com>",
|
|
6
6
|
"license": "MIT OR Apache-2.0",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dist/**/*.d.ts.map"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@sebastienrousseau/crypto-lib": "0.0.
|
|
40
|
+
"@sebastienrousseau/crypto-lib": "0.0.36"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/chai": "^5.2.3",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"format": "prettier --write src/**/*.ts",
|
|
76
76
|
"format:check": "prettier --check \"src/**/*.ts\"",
|
|
77
77
|
"test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --reporter=lcov --reporter=text mocha --config=.mocharc.cjs",
|
|
78
|
+
"test:run": "mocha --config=.mocharc.cjs",
|
|
78
79
|
"docs": "typedoc"
|
|
79
80
|
}
|
|
80
81
|
}
|