@sebastienrousseau/crypto-benchmarks 0.0.34 → 0.0.35
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/timer.d.ts.map +1 -1
- package/dist/timer.js +38 -31
- package/package.json +2 -2
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.35",
|
|
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.35"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/chai": "^5.2.3",
|