@indutny/bencher 1.0.0 → 1.1.0

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
@@ -25,7 +25,7 @@ npm install -g @indutny/bencher
25
25
 
26
26
  ```js
27
27
  // benchmark.js
28
- export const name = 'benchmark name';
28
+ export const name = 'runner';
29
29
 
30
30
  // Function to benchmark
31
31
  export default () => {
@@ -23,14 +23,44 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  __setModuleDefault(result, mod);
24
24
  return result;
25
25
  };
26
+ var __importDefault = (this && this.__importDefault) || function (mod) {
27
+ return (mod && mod.__esModule) ? mod : { "default": mod };
28
+ };
26
29
  Object.defineProperty(exports, "__esModule", { value: true });
27
30
  const promises_1 = require("fs/promises");
31
+ const yargs_1 = __importDefault(require("yargs"));
32
+ const helpers_1 = require("yargs/helpers");
28
33
  async function main() {
29
- const modules = await Promise.all(process.argv.slice(2).map(async (file) => {
34
+ const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
35
+ .alias('h', 'help')
36
+ .option('d', {
37
+ alias: 'duration',
38
+ type: 'number',
39
+ default: 5,
40
+ describe: 'maximum duration in seconds per runner',
41
+ })
42
+ .option('s', {
43
+ alias: 'samples',
44
+ type: 'number',
45
+ default: 100,
46
+ describe: 'number of samples to collect per runner',
47
+ })
48
+ .option('w', {
49
+ alias: 'sweep-width',
50
+ type: 'number',
51
+ default: 10,
52
+ describe: 'width of iteration sweep',
53
+ })
54
+ .option('warm-up-iterations', {
55
+ type: 'number',
56
+ default: 100,
57
+ describe: 'number of warm up iterations',
58
+ }).argv;
59
+ const modules = await Promise.all(argv._.map(async (file) => {
30
60
  var _a;
31
- const path = await (0, promises_1.realpath)(file);
61
+ const path = await (0, promises_1.realpath)(String(file));
32
62
  const m = await (_a = path, Promise.resolve().then(() => __importStar(require(_a))));
33
- const { duration = 5, sweepWidth = 10, samples = 100, warmUpIterations = 100, } = m.options ?? {};
63
+ const { duration = argv['duration'], sweepWidth = argv['sweepWidth'], samples = argv['samples'], warmUpIterations = argv['warmUpIterations'], } = m.options ?? {};
34
64
  if (duration <= 0) {
35
65
  throw new Error(`${file}: options.duration must be positive`);
36
66
  }
@@ -47,7 +77,7 @@ async function main() {
47
77
  throw new Error(`${file}: options.warmUpIterations must be positive`);
48
78
  }
49
79
  return {
50
- name: m.name ?? file,
80
+ name: m.name ?? String(file),
51
81
  options: {
52
82
  duration,
53
83
  sweepWidth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indutny/bencher",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Simple benchmarking tool",
5
5
  "bin": {
6
6
  "bencher": "./dist/bin/bencher.js"
@@ -32,11 +32,15 @@
32
32
  },
33
33
  "homepage": "https://github.com/indutny/bencher#readme",
34
34
  "devDependencies": {
35
+ "@types/yargs": "^17.0.17",
35
36
  "@typescript-eslint/eslint-plugin": "^5.47.0",
36
37
  "@typescript-eslint/parser": "^5.47.0",
37
38
  "eslint": "^8.30.0",
38
39
  "prettier": "^2.8.1",
39
40
  "ts-node": "^10.9.1",
40
41
  "typescript": "^4.9.4"
42
+ },
43
+ "dependencies": {
44
+ "yargs": "^17.6.2"
41
45
  }
42
46
  }