@sebastienrousseau/crypto-benchmarks 0.0.7 → 0.0.9

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/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAOA,wBAAsB,GAAG,CACvB,IAAI,GAAE,MAAM,EAA0B,GACrC,OAAO,CAAC,MAAM,CAAC,CAsDjB"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAuCA,wBAAsB,GAAG,CACvB,IAAI,GAAE,MAAM,EAA0B,GACrC,OAAO,CAAC,MAAM,CAAC,CA8BjB"}
package/dist/cli.js CHANGED
@@ -7,6 +7,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.run = run;
8
8
  const node_process_1 = __importDefault(require("node:process"));
9
9
  const runner_1 = require("./runner");
10
+ const SUITES = [
11
+ "all",
12
+ "symmetric",
13
+ "asymmetric",
14
+ "pqc",
15
+ "hash",
16
+ ];
17
+ const FORMATS = ["table", "json", "markdown"];
18
+ function optionValue(args, flag) {
19
+ const idx = args.indexOf(flag);
20
+ return idx !== -1 && args[idx + 1] ? args[idx + 1] : undefined;
21
+ }
22
+ function pickChoice(args, flag, allowed, fallback) {
23
+ const value = optionValue(args, flag)?.toLowerCase();
24
+ return allowed.find((a) => a === value) ?? fallback;
25
+ }
26
+ function parseIterations(raw) {
27
+ const parsed = raw === undefined ? NaN : parseInt(raw, 10);
28
+ return !isNaN(parsed) && parsed > 0 ? parsed : 30;
29
+ }
10
30
  async function run(args = node_process_1.default.argv.slice(2)) {
11
31
  if (args.includes("--help") || args.includes("-h")) {
12
32
  node_process_1.default.stdout.write("Usage: crypto-benchmarks [options]\n");
@@ -16,40 +36,16 @@ async function run(args = node_process_1.default.argv.slice(2)) {
16
36
  node_process_1.default.stdout.write(" --format <table|json|markdown> Output format (default: table)\n");
17
37
  return 0;
18
38
  }
19
- let suite = "all";
20
- const suiteIdx = args.indexOf("--suite");
21
- if (suiteIdx !== -1 && args[suiteIdx + 1]) {
22
- const s = args[suiteIdx + 1].toLowerCase();
23
- if (["all", "symmetric", "asymmetric", "pqc", "hash"].includes(s)) {
24
- suite = s;
25
- }
26
- }
27
- let iterations = 30;
28
- const iterIdx = args.indexOf("--iterations");
29
- if (iterIdx !== -1 && args[iterIdx + 1]) {
30
- const parsed = parseInt(args[iterIdx + 1], 10);
31
- if (!isNaN(parsed) && parsed > 0) {
32
- iterations = parsed;
33
- }
34
- }
35
- let format = "table";
36
- const formatIdx = args.indexOf("--format");
37
- if (formatIdx !== -1 && args[formatIdx + 1]) {
38
- const f = args[formatIdx + 1].toLowerCase();
39
- if (["table", "json", "markdown"].includes(f)) {
40
- format = f;
41
- }
42
- }
39
+ const suite = pickChoice(args, "--suite", SUITES, "all");
40
+ const iterations = parseIterations(optionValue(args, "--iterations"));
41
+ const format = pickChoice(args, "--format", FORMATS, "table");
43
42
  const report = await (0, runner_1.runSuite)({ suite, iterations, format });
44
- if (format === "json") {
45
- node_process_1.default.stdout.write(JSON.stringify(report, null, 2) + "\n");
46
- }
47
- else if (format === "markdown") {
48
- node_process_1.default.stdout.write(report.summaryMarkdown + "\n");
49
- }
50
- else {
51
- node_process_1.default.stdout.write(report.summaryTable + "\n");
52
- }
43
+ const output = {
44
+ json: () => JSON.stringify(report, null, 2),
45
+ markdown: () => report.summaryMarkdown,
46
+ table: () => report.summaryTable,
47
+ };
48
+ node_process_1.default.stdout.write(output[format]() + "\n");
53
49
  return 0;
54
50
  }
55
51
  if (require.main === module) {
package/dist/runner.js CHANGED
@@ -14,17 +14,16 @@ async function runSuite(config = {}) {
14
14
  const suite = config.suite || "all";
15
15
  const iterations = config.iterations || 30;
16
16
  const results = [];
17
- if (suite === "all" || suite === "symmetric") {
18
- results.push(...(await (0, symmetric_1.runSymmetricBenchmarks)(iterations)));
19
- }
20
- if (suite === "all" || suite === "asymmetric") {
21
- results.push(...(await (0, asymmetric_1.runAsymmetricBenchmarks)(iterations)));
22
- }
23
- if (suite === "all" || suite === "pqc") {
24
- results.push(...(await (0, pqc_1.runPqcBenchmarks)(iterations)));
25
- }
26
- if (suite === "all" || suite === "hash") {
27
- results.push(...(await (0, hash_1.runHashBenchmarks)(iterations)));
17
+ const suites = {
18
+ symmetric: symmetric_1.runSymmetricBenchmarks,
19
+ asymmetric: asymmetric_1.runAsymmetricBenchmarks,
20
+ pqc: pqc_1.runPqcBenchmarks,
21
+ hash: hash_1.runHashBenchmarks,
22
+ };
23
+ for (const [name, run] of Object.entries(suites)) {
24
+ if (suite === "all" || suite === name) {
25
+ results.push(...(await run(iterations)));
26
+ }
28
27
  }
29
28
  const timestamp = new Date().toISOString();
30
29
  const platform = `${node_os_1.default.platform()} ${node_os_1.default.arch()}`;
@@ -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;AAKD,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,EAC9B,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,cAAc,CAAC,CAmEzB"}
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"}
package/dist/timer.js CHANGED
@@ -5,23 +5,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.benchmarkOperation = benchmarkOperation;
7
7
  const node_process_1 = __importDefault(require("node:process"));
8
+ async function runOnce(fn) {
9
+ const res = fn();
10
+ if (res instanceof Promise) {
11
+ await res;
12
+ }
13
+ }
8
14
  async function benchmarkOperation(fn, options = {}) {
9
15
  const iterations = options.iterations && options.iterations > 0 ? options.iterations : 10;
10
16
  const warmup = options.warmup !== undefined && options.warmup >= 0 ? options.warmup : 2;
11
17
  for (let i = 0; i < warmup; i++) {
12
- const res = fn();
13
- if (res instanceof Promise) {
14
- await res;
15
- }
18
+ await runOnce(fn);
16
19
  }
17
20
  const timesMs = [];
18
21
  const startTotal = node_process_1.default.hrtime.bigint();
19
22
  for (let i = 0; i < iterations; i++) {
20
23
  const start = node_process_1.default.hrtime.bigint();
21
- const res = fn();
22
- if (res instanceof Promise) {
23
- await res;
24
- }
24
+ await runOnce(fn);
25
25
  const end = node_process_1.default.hrtime.bigint();
26
26
  const diffMs = Number(end - start) / 1_000_000;
27
27
  timesMs.push(diffMs);
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@sebastienrousseau/crypto-benchmarks",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "Performance benchmarking and latency profiling harness comparing classical vs post-quantum cryptographic primitives across JavaScript, WebAssembly, and native runtimes.",
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",
8
8
  "repository": {
9
- "directory": "packages/crypto-benchmarks",
10
9
  "type": "git",
11
- "url": "git@github.com:sebastienrousseau/crypto-service.git"
10
+ "url": "git+https://github.com/sebastienrousseau/crypto-service.git",
11
+ "directory": "packages/crypto-benchmarks"
12
12
  },
13
13
  "bugs": {
14
14
  "url": "https://github.com/sebastienrousseau/crypto-service/issues"
@@ -16,8 +16,17 @@
16
16
  "engines": {
17
17
  "node": ">=22.0.0"
18
18
  },
19
+ "type": "commonjs",
19
20
  "main": "./dist/index.js",
20
21
  "types": "./dist/index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./dist/index.d.ts",
25
+ "require": "./dist/index.js",
26
+ "default": "./dist/index.js"
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
21
30
  "sideEffects": false,
22
31
  "bin": {
23
32
  "crypto-benchmarks": "./dist/cli.js"
@@ -28,17 +37,17 @@
28
37
  "dist/**/*.d.ts.map"
29
38
  ],
30
39
  "dependencies": {
31
- "@sebastienrousseau/crypto-lib": "0.0.7"
40
+ "@sebastienrousseau/crypto-lib": "0.0.9"
32
41
  },
33
42
  "devDependencies": {
34
- "@types/chai": "^4.3.7",
43
+ "@types/chai": "^5.2.3",
35
44
  "@types/chai-as-promised": "^8.0.2",
36
- "@types/mocha": "^10.0.2",
37
- "@types/node": "^26.4.1",
45
+ "@types/mocha": "^10.0.10",
46
+ "@types/node": "^26.6.3",
38
47
  "c8": "^12.0.0",
39
- "chai": "^4.5.0",
40
- "chai-as-promised": "^7.1.2",
41
- "mocha": "^10.8.2",
48
+ "chai": "^6.3.0",
49
+ "chai-as-promised": "^8.0.2",
50
+ "mocha": "^12.0.3",
42
51
  "rimraf": "^6.1.3",
43
52
  "ts-node": "^10.9.2",
44
53
  "typedoc": "^0.28.20",
@@ -50,8 +59,8 @@
50
59
  "scripts": {
51
60
  "build": "tsc --build tsconfig.json",
52
61
  "clean": "rimraf ./coverage ./dist ./docs",
53
- "lint": "eslint --ext .ts src __tests__",
54
- "lint:fix": "eslint --cache --fix --ext .ts src __tests__",
62
+ "lint": "eslint src __tests__",
63
+ "lint:fix": "eslint --cache --fix src __tests__",
55
64
  "format": "prettier --write src/**/*.ts",
56
65
  "format:check": "prettier --check \"src/**/*.ts\"",
57
66
  "test": "c8 --check-coverage --lines 100 --branches 100 --functions 100 --reporter=lcov --reporter=text mocha --config=.mocharc.cjs",