@sebastienrousseau/crypto-benchmarks 0.0.33 → 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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # `@sebastienrousseau/crypto-benchmarks`
4
4
 
5
- > Performance benchmarking and latency profiling harness comparing classical vs post-quantum cryptographic primitives across JavaScript, WebAssembly, and native runtimes.
5
+ > 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.
6
6
 
7
7
  [![Version](https://img.shields.io/npm/v/@sebastienrousseau/crypto-benchmarks.svg)](https://www.npmjs.com/package/@sebastienrousseau/crypto-benchmarks)
8
8
  [![License](https://img.shields.io/badge/license-MIT%20OR%20Apache--2.0-blue.svg)](https://opensource.org/licenses/MIT)
@@ -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;AAaD,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC9B,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,cAAc,CAAC,CA6DzB"}
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
- async function benchmarkOperation(fn, options = {}) {
15
- const iterations = options.iterations && options.iterations > 0 ? options.iterations : 10;
16
- const warmup = options.warmup !== undefined && options.warmup >= 0 ? options.warmup : 2;
17
- for (let i = 0; i < warmup; i++) {
18
- await runOnce(fn);
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
- const end = node_process_1.default.hrtime.bigint();
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 endTotal = node_process_1.default.hrtime.bigint();
30
- const totalDurationMs = Number(endTotal - startTotal) / 1_000_000;
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: Number(meanMs.toFixed(4)),
47
- medianMs: Number(medianMs.toFixed(4)),
48
- minMs: Number(minMs.toFixed(4)),
49
- maxMs: Number(maxMs.toFixed(4)),
50
- p95Ms: Number(p95Ms.toFixed(4)),
51
- p99Ms: Number(p99Ms.toFixed(4)),
52
- opsPerSec: Math.round(opsPerSec),
53
- totalDurationMs: Number(totalDurationMs.toFixed(4)),
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,7 +1,7 @@
1
1
  {
2
2
  "name": "@sebastienrousseau/crypto-benchmarks",
3
- "version": "0.0.33",
4
- "description": "Performance benchmarking and latency profiling harness comparing classical vs post-quantum cryptographic primitives across JavaScript, WebAssembly, and native runtimes.",
3
+ "version": "0.0.35",
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",
7
7
  "homepage": "https://crypto-service.co",
@@ -37,7 +37,7 @@
37
37
  "dist/**/*.d.ts.map"
38
38
  ],
39
39
  "dependencies": {
40
- "@sebastienrousseau/crypto-lib": "0.0.33"
40
+ "@sebastienrousseau/crypto-lib": "0.0.35"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@types/chai": "^5.2.3",
@@ -56,6 +56,17 @@
56
56
  "publishConfig": {
57
57
  "access": "public"
58
58
  },
59
+ "keywords": [
60
+ "benchmark",
61
+ "performance",
62
+ "cryptography",
63
+ "post-quantum",
64
+ "pqc",
65
+ "ml-kem",
66
+ "ml-dsa",
67
+ "latency",
68
+ "throughput"
69
+ ],
59
70
  "scripts": {
60
71
  "build": "tsc --build tsconfig.json",
61
72
  "clean": "rimraf ./coverage ./dist ./docs",