flexi-bench 0.0.0-alpha.3 → 0.0.0-alpha.4

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/variation.js CHANGED
@@ -1,15 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Variation = void 0;
4
- class Variation {
4
+ const shared_api_1 = require("./shared-api");
5
+ const utils_1 = require("./utils");
6
+ class Variation extends shared_api_1.BenchmarkBase {
5
7
  constructor(name) {
8
+ super();
6
9
  this.name = name;
7
- this.setupMethods = [];
8
- this.teardownMethods = [];
9
10
  this.environment = {};
11
+ this.cliArgs = [];
10
12
  }
11
13
  static FromEnvironmentVariables(variables) {
12
- const combinations = variables.reduce((acc, [name, values]) => {
14
+ const combinations = (0, utils_1.findCombinations)(variables.map(([name, values]) => values.map((value) => [name, value])));
15
+ variables.reduce((acc, [name, values]) => {
13
16
  return acc.flatMap((accItem) => {
14
17
  return values.map((value) => {
15
18
  return [...accItem, [name, value]];
@@ -21,13 +24,30 @@ class Variation {
21
24
  return new Variation(label).withEnvironmentVariables(Object.fromEntries(combination));
22
25
  });
23
26
  }
24
- withSetup(setup) {
25
- this.setupMethods.push(setup);
26
- return this;
27
- }
28
- withTeardown(teardown) {
29
- this.teardownMethods.push(teardown);
30
- return this;
27
+ /**
28
+ *
29
+ * @param args An array of options to pass to the CLI. If an element is an array, they will be treated as alternatives.
30
+ * @returns An array of variations. Can be applied with `withVariations`.
31
+ * @example
32
+ * // Creates 2 variations, both with --flag, but one with --no-daemon and the other with --daemon.
33
+ * const variations = Variation.FromCliArgs([
34
+ * '--flag',
35
+ * ['--no-daemon', '--daemon'],
36
+ * ]);
37
+ *
38
+ * // Creates 4 variations, with combinations of --a and --b.
39
+ * const variations = Variation.FromCliArgs([
40
+ * ['--a', '--b'],
41
+ * ]);
42
+ */
43
+ static FromCliArgs(args) {
44
+ const alternatives = args.filter(Array.isArray);
45
+ const values = (0, utils_1.findCombinations)(alternatives);
46
+ return values.flatMap((alts) => {
47
+ const cliArgs = args.map((arg) => Array.isArray(arg) ? alts.shift() : arg);
48
+ const label = cliArgs.join(' ');
49
+ return new Variation(label).withCliArgs(...cliArgs);
50
+ });
31
51
  }
32
52
  withEnvironmentVariables(env) {
33
53
  this.environment = Object.assign(Object.assign({}, this.environment), env);
@@ -37,8 +57,8 @@ class Variation {
37
57
  this.environment[name] = value;
38
58
  return this;
39
59
  }
40
- withAction(action) {
41
- this.action = action;
60
+ withCliArgs(...args) {
61
+ this.cliArgs = this.cliArgs.concat(args);
42
62
  return this;
43
63
  }
44
64
  }
package/package.json CHANGED
@@ -1,35 +1,49 @@
1
1
  {
2
2
  "name": "flexi-bench",
3
- "version": "0.0.0-alpha.3",
3
+ "version": "0.0.0-alpha.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/AgentEnder/flexi-bench"
9
+ },
6
10
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1",
11
+ "test": "node --import tsx --test './src/**/*.spec.ts'",
12
+ "test:watch": "node --import tsx --test --watch './src/**/*.spec.ts'",
8
13
  "build": "tsc -p tsconfig.json",
9
14
  "format": "prettier --write src"
10
15
  },
11
16
  "author": "",
12
- "license": "ISC",
17
+ "license": "MIT",
13
18
  "devDependencies": {
14
19
  "@nx/js": "^19.4.2",
15
20
  "@swc-node/register": "~1.9.1",
16
21
  "@swc/core": "~1.5.7",
17
22
  "@swc/helpers": "~0.5.11",
18
- "nx": "19.4.2"
19
- },
20
- "nx": {},
21
- "dependencies": {
22
23
  "@types/cli-progress": "^3.11.6",
23
24
  "@types/node": "^20.14.10",
24
- "cli-progress": "^3.12.0",
25
+ "nx": "19.4.2",
25
26
  "prettier": "^3.3.2",
26
- "typescript": "^5.5.3"
27
+ "ts-node": "^10.9.2",
28
+ "tsx": "^4.16.2",
29
+ "typescript": "^5.5.3",
30
+ "yaml": "^2.4.5"
27
31
  },
32
+ "dependencies": {
33
+ "cli-progress": "^3.12.0",
34
+ "markdown-factory": "^0.0.6"
35
+ },
36
+ "nx": {},
28
37
  "files": [
29
38
  "dist",
30
39
  "README.md",
31
40
  "LICENSE",
32
41
  "CHANGELOG.md",
33
42
  "package.json"
43
+ ],
44
+ "workspaces": [
45
+ ".",
46
+ "docs-site",
47
+ "packages/*"
34
48
  ]
35
49
  }
@@ -1,8 +0,0 @@
1
- import { Result, Reporter, ProgressContext } from './api-types';
2
- import { Benchmark } from './benchmark';
3
- export declare class ConsoleReporter implements Reporter {
4
- private bar;
5
- constructor();
6
- progress(name: string, percent: number, context: ProgressContext): void;
7
- report(benchmark: Benchmark, results: Result[]): void;
8
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConsoleReporter = void 0;
4
- const cli_progress_1 = require("cli-progress");
5
- class ConsoleReporter {
6
- constructor() {
7
- this.bar = new cli_progress_1.SingleBar({
8
- format: 'Running: {label}\n{bar} {percentage}% | {value}/{total} - ETA: {eta}s',
9
- barCompleteChar: '\u2588',
10
- barIncompleteChar: '\u2591',
11
- hideCursor: true,
12
- });
13
- }
14
- progress(name, percent, context) {
15
- var _a;
16
- if (!this.bar.isActive) {
17
- this.bar.start((_a = context.totalIterations) !== null && _a !== void 0 ? _a : 100, 0);
18
- }
19
- this.bar.update(context.completedIterations, { label: name });
20
- process.stdout.moveCursor(0, -1);
21
- // console.log(`Progress: ${name} ${Math.round(percent * 10000) / 100}%`);
22
- }
23
- report(benchmark, results) {
24
- this.bar.stop();
25
- process.stdout.moveCursor(0, -1);
26
- process.stdout.clearScreenDown();
27
- console.log(`Benchmark: ${benchmark.name}`);
28
- console.table(results);
29
- }
30
- }
31
- exports.ConsoleReporter = ConsoleReporter;