overtake 1.0.0-rc.0 → 1.0.0-rc.3

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.
Files changed (44) hide show
  1. package/README.md +4 -3
  2. package/build/cli.cjs +8 -8
  3. package/build/cli.cjs.map +1 -1
  4. package/build/cli.js +2 -2
  5. package/build/cli.js.map +1 -1
  6. package/build/executor.cjs.map +1 -1
  7. package/build/executor.js.map +1 -1
  8. package/build/index.cjs +228 -11
  9. package/build/index.cjs.map +1 -1
  10. package/build/index.d.ts +65 -3
  11. package/build/index.js +187 -1
  12. package/build/index.js.map +1 -1
  13. package/build/queue.cjs.map +1 -1
  14. package/build/queue.js.map +1 -1
  15. package/build/reporter.cjs +1 -1
  16. package/build/reporter.cjs.map +1 -1
  17. package/build/reporter.js +1 -1
  18. package/build/reporter.js.map +1 -1
  19. package/build/runner.cjs.map +1 -1
  20. package/build/runner.js.map +1 -1
  21. package/build/types.cjs.map +1 -1
  22. package/build/types.js.map +1 -1
  23. package/build/utils.cjs +2 -2
  24. package/build/utils.cjs.map +1 -1
  25. package/build/utils.js +2 -2
  26. package/build/utils.js.map +1 -1
  27. package/examples/array-copy.ts +17 -0
  28. package/package.json +3 -3
  29. package/src/cli.ts +2 -2
  30. package/src/index.ts +232 -3
  31. package/src/reporter.ts +1 -1
  32. package/build/__tests__/runner.d.ts +0 -1
  33. package/build/benchmark.cjs +0 -237
  34. package/build/benchmark.cjs.map +0 -1
  35. package/build/benchmark.d.ts +0 -64
  36. package/build/benchmark.js +0 -189
  37. package/build/benchmark.js.map +0 -1
  38. package/overtakes/array-copy.md +0 -80
  39. package/overtakes/array-delete-element.md +0 -44
  40. package/overtakes/async.md +0 -25
  41. package/overtakes/class-vs-function.md +0 -31
  42. package/overtakes/postgres-vs-mongo.md +0 -55
  43. package/src/__tests__/runner.ts +0 -34
  44. package/src/benchmark.ts +0 -231
package/README.md CHANGED
@@ -5,9 +5,10 @@ Performance benchmark for NodeJS
5
5
  [![Build Status][github-image]][github-url]
6
6
  [![NPM version][npm-image]][npm-url]
7
7
  [![Downloads][downloads-image]][npm-url]
8
- [![Coverage Status][codecov-image]][codecov-url]
9
- [![Maintainability][codeclimate-image]][codeclimate-url]
10
- [![Snyk][snyk-image]][snyk-url]
8
+
9
+ <!--[![Coverage Status][codecov-image]][codecov-url]-->
10
+ <!--[![Maintainability][codeclimate-image]][codeclimate-url]-->
11
+ <!--[![Snyk][snyk-image]][snyk-url]-->
11
12
 
12
13
  ## Table of Contents
13
14
 
package/build/cli.cjs CHANGED
@@ -8,7 +8,7 @@ const _promises = require("node:fs/promises");
8
8
  const _core = require("@swc/core");
9
9
  const _commander = require("commander");
10
10
  const _glob = require("glob");
11
- const _benchmarkcjs = require("./benchmark.cjs");
11
+ const _indexcjs = require("./index.cjs");
12
12
  const _typescjs = require("./types.cjs");
13
13
  function _getRequireWildcardCache(nodeInterop) {
14
14
  if (typeof WeakMap !== "function") return null;
@@ -67,14 +67,14 @@ const transpile = async (code)=>{
67
67
  jsc: {
68
68
  target: 'esnext',
69
69
  parser: {
70
- syntax: "typescript"
70
+ syntax: 'typescript'
71
71
  },
72
72
  experimental: {}
73
73
  }
74
74
  });
75
75
  return output.code;
76
76
  };
77
- commander.name(name).description(description).version(version).argument('<path>', 'glob pattern to find benchmarks').addOption(new _commander.Option('-r, --report-types [reportTypes...]', 'statistic types to include in the report').choices(_typescjs.REPORT_TYPES).default(_benchmarkcjs.DEFAULT_REPORT_TYPES)).addOption(new _commander.Option('-w, --workers [workers]', 'number of concurent workers').default(_benchmarkcjs.DEFAULT_WORKERS).argParser(parseInt)).addOption(new _commander.Option('-f, --format [format]', 'output format').default('simple').choices([
77
+ commander.name(name).description(description).version(version).argument('<path>', 'glob pattern to find benchmarks').addOption(new _commander.Option('-r, --report-types [reportTypes...]', 'statistic types to include in the report').choices(_typescjs.REPORT_TYPES).default(_indexcjs.DEFAULT_REPORT_TYPES)).addOption(new _commander.Option('-w, --workers [workers]', 'number of concurent workers').default(_indexcjs.DEFAULT_WORKERS).argParser(parseInt)).addOption(new _commander.Option('-f, --format [format]', 'output format').default('simple').choices([
78
78
  'simple',
79
79
  'json',
80
80
  'pjson',
@@ -94,7 +94,7 @@ commander.name(name).description(description).version(version).argument('<path>'
94
94
  if (instance) {
95
95
  throw new Error('Only one benchmark per file is supported');
96
96
  }
97
- instance = _benchmarkcjs.Benchmark.create(...args);
97
+ instance = _indexcjs.Benchmark.create(...args);
98
98
  return instance;
99
99
  };
100
100
  const script = new _nodevm.SourceTextModule(code, {
@@ -124,21 +124,21 @@ commander.name(name).description(description).version(version).argument('<path>'
124
124
  switch(executeOptions.format){
125
125
  case 'json':
126
126
  {
127
- (0, _benchmarkcjs.printJSONReports)(reports);
127
+ (0, _indexcjs.printJSONReports)(reports);
128
128
  }
129
129
  break;
130
130
  case 'pjson':
131
131
  {
132
- (0, _benchmarkcjs.printJSONReports)(reports, 2);
132
+ (0, _indexcjs.printJSONReports)(reports, 2);
133
133
  }
134
134
  break;
135
135
  case 'table':
136
136
  {
137
- (0, _benchmarkcjs.printTableReports)(reports);
137
+ (0, _indexcjs.printTableReports)(reports);
138
138
  }
139
139
  break;
140
140
  default:
141
- (0, _benchmarkcjs.printSimpleReports)(reports);
141
+ (0, _indexcjs.printSimpleReports)(reports);
142
142
  }
143
143
  }
144
144
  }
package/build/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["import { createRequire, Module } from 'node:module';\nimport { SyntheticModule, createContext, SourceTextModule, Module as VMModule } from 'node:vm';\nimport { stat, readFile } from 'node:fs/promises';\nimport { parse, print } from '@swc/core';\nimport { Command, Option } from 'commander';\nimport { glob } from 'glob';\nimport { Benchmark, printTableReports, printJSONReports, printSimpleReports, DEFAULT_REPORT_TYPES, DEFAULT_WORKERS } from './benchmark.js';\nimport { REPORT_TYPES } from './types.js';\n\nconst require = createRequire(import.meta.url);\nconst { name, description, version } = require('../package.json');\n\nconst commander = new Command();\n\nconst transpile = async (code: string): Promise<string> => {\n const ast = await parse(code, {\n syntax: 'typescript',\n dynamicImport: true,\n target: 'esnext'\n });\n\n const output = await print(ast, {\n module: {\n type: 'es6',\n },\n jsc: {\n target: 'esnext',\n parser: {\n syntax: \"typescript\",\n },\n experimental: {\n\n }\n }\n });\n return output.code;\n};\n\ncommander\n .name(name)\n .description(description)\n .version(version)\n .argument('<path>', 'glob pattern to find benchmarks')\n .addOption(new Option('-r, --report-types [reportTypes...]', 'statistic types to include in the report').choices(REPORT_TYPES).default(DEFAULT_REPORT_TYPES))\n .addOption(new Option('-w, --workers [workers]', 'number of concurent workers').default(DEFAULT_WORKERS).argParser(parseInt))\n .addOption(new Option('-f, --format [format]', 'output format').default('simple').choices(['simple', 'json', 'pjson', 'table']))\n .addOption(new Option('--abs-threshold [absThreshold]', 'absolute error threshold in nanoseconds').argParser(parseInt))\n .addOption(new Option('--rel-threshold [relThreshold]', 'relative error threshold (fraction between 0 and 1)').argParser(parseInt))\n .addOption(new Option('--warmup-cycles [warmupCycles]', 'number of warmup cycles before measuring').argParser(parseInt))\n .addOption(new Option('--max-cycles [maxCycles]', 'maximum measurement cycles per feed').argParser(parseInt))\n .addOption(new Option('--min-cycles [minCycles]', 'minimum measurement cycles per feed').argParser(parseInt))\n .action(async (path, executeOptions) => {\n const files = await glob(path, { absolute: true, cwd: process.cwd() }).catch(() => []);\n for (const file of files) {\n const stats = await stat(file).catch(() => false as const);\n if (stats && stats.isFile()) {\n const content = await readFile(file, 'utf8');\n const code = await transpile(content);\n let instance: Benchmark<unknown> | undefined;\n const benchmark = (...args: Parameters<typeof Benchmark[\"create\"]>) => {\n if (instance) {\n throw new Error('Only one benchmark per file is supported');\n }\n instance = Benchmark.create(...args);\n return instance;\n };\n const script = new SourceTextModule(code, {\n context: createContext({ benchmark }),\n });\n const imports = new Map();\n await script.link(async (specifier: string, referencingModule) => {\n if (imports.has(specifier)) {\n return imports.get(specifier);\n }\n const mod = await import(Module.isBuiltin(specifier) ? specifier : require.resolve(specifier));\n const exportNames = Object.keys(mod);\n const imported = new SyntheticModule(\n exportNames,\n () => {\n exportNames.forEach((key) => imported.setExport(key, mod[key]));\n },\n { identifier: specifier, context: referencingModule.context },\n );\n\n imports.set(specifier, imported);\n return imported;\n });\n await script.evaluate();\n\n if (instance) {\n const reports = await instance.execute(executeOptions);\n switch (executeOptions.format) {\n case 'json': {\n printJSONReports(reports);\n } break;\n case 'pjson': {\n printJSONReports(reports, 2);\n } break;\n case 'table': {\n printTableReports(reports);\n } break;\n default:\n printSimpleReports(reports);\n }\n }\n }\n }\n });\n\ncommander.parse(process.argv);\n\n"],"names":["require","createRequire","name","description","version","commander","Command","transpile","code","ast","parse","syntax","dynamicImport","target","output","print","module","type","jsc","parser","experimental","argument","addOption","Option","choices","REPORT_TYPES","default","DEFAULT_REPORT_TYPES","DEFAULT_WORKERS","argParser","parseInt","action","path","executeOptions","files","glob","absolute","cwd","process","catch","file","stats","stat","isFile","content","readFile","instance","benchmark","args","Error","Benchmark","create","script","SourceTextModule","context","createContext","imports","Map","link","specifier","referencingModule","has","get","mod","Module","isBuiltin","resolve","exportNames","Object","keys","imported","SyntheticModule","forEach","key","setExport","identifier","set","evaluate","reports","execute","format","printJSONReports","printTableReports","printSimpleReports","argv"],"mappings":";;;;4BAAsC;wBAC+C;0BACtD;sBACF;2BACG;sBACX;8BACqG;0BAC7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7B,MAAMA,WAAUC,IAAAA,yBAAa,EAAC;AAC9B,MAAM,EAAEC,IAAI,EAAEC,WAAW,EAAEC,OAAO,EAAE,GAAGJ,SAAQ;AAE/C,MAAMK,YAAY,IAAIC,kBAAO;AAE7B,MAAMC,YAAY,OAAOC;IACvB,MAAMC,MAAM,MAAMC,IAAAA,WAAK,EAACF,MAAM;QAC5BG,QAAQ;QACRC,eAAe;QACfC,QAAQ;IACV;IAEA,MAAMC,SAAS,MAAMC,IAAAA,WAA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;wBACpB;wBAAE;oBACF;wBACEK,IAAAA,gCAAkB,EAACL;gBACvB;YACF;QACF;IACF;AACF;AAEFzE,UAAUK,KAAK,CAAC4B,QAAQ8C,IAAI"}
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["import { createRequire, Module } from 'node:module';\nimport { SyntheticModule, createContext, SourceTextModule } from 'node:vm';\nimport { stat, readFile } from 'node:fs/promises';\nimport { parse, print } from '@swc/core';\nimport { Command, Option } from 'commander';\nimport { glob } from 'glob';\nimport { Benchmark, printTableReports, printJSONReports, printSimpleReports, DEFAULT_REPORT_TYPES, DEFAULT_WORKERS } from './index.js';\nimport { REPORT_TYPES } from './types.js';\n\nconst require = createRequire(import.meta.url);\nconst { name, description, version } = require('../package.json');\n\nconst commander = new Command();\n\nconst transpile = async (code: string): Promise<string> => {\n const ast = await parse(code, {\n syntax: 'typescript',\n dynamicImport: true,\n target: 'esnext',\n });\n\n const output = await print(ast, {\n module: {\n type: 'es6',\n },\n jsc: {\n target: 'esnext',\n parser: {\n syntax: 'typescript',\n },\n experimental: {},\n },\n });\n return output.code;\n};\n\ncommander\n .name(name)\n .description(description)\n .version(version)\n .argument('<path>', 'glob pattern to find benchmarks')\n .addOption(new Option('-r, --report-types [reportTypes...]', 'statistic types to include in the report').choices(REPORT_TYPES).default(DEFAULT_REPORT_TYPES))\n .addOption(new Option('-w, --workers [workers]', 'number of concurent workers').default(DEFAULT_WORKERS).argParser(parseInt))\n .addOption(new Option('-f, --format [format]', 'output format').default('simple').choices(['simple', 'json', 'pjson', 'table']))\n .addOption(new Option('--abs-threshold [absThreshold]', 'absolute error threshold in nanoseconds').argParser(parseInt))\n .addOption(new Option('--rel-threshold [relThreshold]', 'relative error threshold (fraction between 0 and 1)').argParser(parseInt))\n .addOption(new Option('--warmup-cycles [warmupCycles]', 'number of warmup cycles before measuring').argParser(parseInt))\n .addOption(new Option('--max-cycles [maxCycles]', 'maximum measurement cycles per feed').argParser(parseInt))\n .addOption(new Option('--min-cycles [minCycles]', 'minimum measurement cycles per feed').argParser(parseInt))\n .action(async (path, executeOptions) => {\n const files = await glob(path, { absolute: true, cwd: process.cwd() }).catch(() => []);\n for (const file of files) {\n const stats = await stat(file).catch(() => false as const);\n if (stats && stats.isFile()) {\n const content = await readFile(file, 'utf8');\n const code = await transpile(content);\n let instance: Benchmark<unknown> | undefined;\n const benchmark = (...args: Parameters<(typeof Benchmark)['create']>) => {\n if (instance) {\n throw new Error('Only one benchmark per file is supported');\n }\n instance = Benchmark.create(...args);\n return instance;\n };\n const script = new SourceTextModule(code, {\n context: createContext({ benchmark }),\n });\n const imports = new Map();\n await script.link(async (specifier: string, referencingModule) => {\n if (imports.has(specifier)) {\n return imports.get(specifier);\n }\n const mod = await import(Module.isBuiltin(specifier) ? specifier : require.resolve(specifier));\n const exportNames = Object.keys(mod);\n const imported = new SyntheticModule(\n exportNames,\n () => {\n exportNames.forEach((key) => imported.setExport(key, mod[key]));\n },\n { identifier: specifier, context: referencingModule.context },\n );\n\n imports.set(specifier, imported);\n return imported;\n });\n await script.evaluate();\n\n if (instance) {\n const reports = await instance.execute(executeOptions);\n switch (executeOptions.format) {\n case 'json':\n {\n printJSONReports(reports);\n }\n break;\n case 'pjson':\n {\n printJSONReports(reports, 2);\n }\n break;\n case 'table':\n {\n printTableReports(reports);\n }\n break;\n default:\n printSimpleReports(reports);\n }\n }\n }\n }\n });\n\ncommander.parse(process.argv);\n"],"names":["require","createRequire","name","description","version","commander","Command","transpile","code","ast","parse","syntax","dynamicImport","target","output","print","module","type","jsc","parser","experimental","argument","addOption","Option","choices","REPORT_TYPES","default","DEFAULT_REPORT_TYPES","DEFAULT_WORKERS","argParser","parseInt","action","path","executeOptions","files","glob","absolute","cwd","process","catch","file","stats","stat","isFile","content","readFile","instance","benchmark","args","Error","Benchmark","create","script","SourceTextModule","context","createContext","imports","Map","link","specifier","referencingModule","has","get","mod","Module","isBuiltin","resolve","exportNames","Object","keys","imported","SyntheticModule","forEach","key","setExport","identifier","set","evaluate","reports","execute","format","printJSONReports","printTableReports","printSimpleReports","argv"],"mappings":";;;;4BAAsC;wBAC2B;0BAClC;sBACF;2BACG;sBACX;0BACqG;0BAC7F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE7B,MAAMA,WAAUC,IAAAA,yBAAa,EAAC;AAC9B,MAAM,EAAEC,IAAI,EAAEC,WAAW,EAAEC,OAAO,EAAE,GAAGJ,SAAQ;AAE/C,MAAMK,YAAY,IAAIC,kBAAO;AAE7B,MAAMC,YAAY,OAAOC;IACvB,MAAMC,MAAM,MAAMC,IAAAA,WAAK,EAACF,MAAM;QAC5BG,QAAQ;QACRC,eAAe;QACfC,QAAQ;IACV;IAEA,MAAMC,SAAS,MAAMC,IAAAA,WAAK,EAACN,KAAK;QAC9BO,QAAQ;YACNC,MAAM;QACR;QACAC,KAAK;YACHL,QAAQ;YACRM,QAAQ;gBACNR,QAAQ;YACV;YACAS,cAAc,CAAC;QACjB;IACF;IACA,OAAON,OAAON,IAAI;AACpB;AAEAH,UACGH,IAAI,CAACA,MACLC,WAAW,CAACA,aACZC,OAAO,CAACA,SACRiB,QAAQ,CAAC,UAAU,mCACnBC,SAAS,CAAC,IAAIC,iBAAM,CAAC,uCAAuC,4CAA4CC,OAAO,CAACC,sBAAY,EAAEC,OAAO,CAACC,8BAAoB,GAC1JL,SAAS,CAAC,IAAIC,iBAAM,CAAC,2BAA2B,+BAA+BG,OAAO,CAACE,yBAAe,EAAEC,SAAS,CAACC,WAClHR,SAAS,CAAC,IAAIC,iBAAM,CAAC,yBAAyB,iBAAiBG,OAAO,CAAC,UAAUF,OAAO,CAAC;IAAC;IAAU;IAAQ;IAAS;CAAQ,GAC7HF,SAAS,CAAC,IAAIC,iBAAM,CAAC,kCAAkC,2CAA2CM,SAAS,CAACC,WAC5GR,SAAS,CAAC,IAAIC,iBAAM,CAAC,kCAAkC,uDAAuDM,SAAS,CAACC,WACxHR,SAAS,CAAC,IAAIC,iBAAM,CA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AASI,SAAS,CAACD,KAAKV,GAAG,CAACU,IAAI;gBAC/D,GACA;oBAAEE,YAAYhB;oBAAWL,SAASM,kBAAkBN,OAAO;gBAAC;gBAG9DE,QAAQoB,GAAG,CAACjB,WAAWW;gBACvB,OAAOA;YACT;YACA,MAAMlB,OAAOyB,QAAQ;YAErB,IAAI/B,UAAU;gBACZ,MAAMgC,UAAU,MAAMhC,SAASiC,OAAO,CAAC9C;gBACvC,OAAQA,eAAe+C,MAAM;oBAC3B,KAAK;wBACH;4BACEC,IAAAA,0BAAgB,EAACH;wBACnB;wBACA;oBACF,KAAK;wBACH;4BACEG,IAAAA,0BAAgB,EAACH,SAAS;wBAC5B;wBACA;oBACF,KAAK;wBACH;4BACEI,IAAAA,2BAAiB,EAACJ;wBACpB;wBACA;oBACF;wBACEK,IAAAA,4BAAkB,EAACL;gBACvB;YACF;QACF;IACF;AACF;AAEFzE,UAAUK,KAAK,CAAC4B,QAAQ8C,IAAI"}
package/build/cli.js CHANGED
@@ -4,7 +4,7 @@ import { stat, readFile } from 'node:fs/promises';
4
4
  import { parse, print } from '@swc/core';
5
5
  import { Command, Option } from 'commander';
6
6
  import { glob } from 'glob';
7
- import { Benchmark, printTableReports, printJSONReports, printSimpleReports, DEFAULT_REPORT_TYPES, DEFAULT_WORKERS } from "./benchmark.js";
7
+ import { Benchmark, printTableReports, printJSONReports, printSimpleReports, DEFAULT_REPORT_TYPES, DEFAULT_WORKERS } from "./index.js";
8
8
  import { REPORT_TYPES } from "./types.js";
9
9
  const require = createRequire(import.meta.url);
10
10
  const { name, description, version } = require('../package.json');
@@ -22,7 +22,7 @@ const transpile = async (code)=>{
22
22
  jsc: {
23
23
  target: 'esnext',
24
24
  parser: {
25
- syntax: "typescript"
25
+ syntax: 'typescript'
26
26
  },
27
27
  experimental: {}
28
28
  }
package/build/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["import { createRequire, Module } from 'node:module';\nimport { SyntheticModule, createContext, SourceTextModule, Module as VMModule } from 'node:vm';\nimport { stat, readFile } from 'node:fs/promises';\nimport { parse, print } from '@swc/core';\nimport { Command, Option } from 'commander';\nimport { glob } from 'glob';\nimport { Benchmark, printTableReports, printJSONReports, printSimpleReports, DEFAULT_REPORT_TYPES, DEFAULT_WORKERS } from './benchmark.js';\nimport { REPORT_TYPES } from './types.js';\n\nconst require = createRequire(import.meta.url);\nconst { name, description, version } = require('../package.json');\n\nconst commander = new Command();\n\nconst transpile = async (code: string): Promise<string> => {\n const ast = await parse(code, {\n syntax: 'typescript',\n dynamicImport: true,\n target: 'esnext'\n });\n\n const output = await print(ast, {\n module: {\n type: 'es6',\n },\n jsc: {\n target: 'esnext',\n parser: {\n syntax: \"typescript\",\n },\n experimental: {\n\n }\n }\n });\n return output.code;\n};\n\ncommander\n .name(name)\n .description(description)\n .version(version)\n .argument('<path>', 'glob pattern to find benchmarks')\n .addOption(new Option('-r, --report-types [reportTypes...]', 'statistic types to include in the report').choices(REPORT_TYPES).default(DEFAULT_REPORT_TYPES))\n .addOption(new Option('-w, --workers [workers]', 'number of concurent workers').default(DEFAULT_WORKERS).argParser(parseInt))\n .addOption(new Option('-f, --format [format]', 'output format').default('simple').choices(['simple', 'json', 'pjson', 'table']))\n .addOption(new Option('--abs-threshold [absThreshold]', 'absolute error threshold in nanoseconds').argParser(parseInt))\n .addOption(new Option('--rel-threshold [relThreshold]', 'relative error threshold (fraction between 0 and 1)').argParser(parseInt))\n .addOption(new Option('--warmup-cycles [warmupCycles]', 'number of warmup cycles before measuring').argParser(parseInt))\n .addOption(new Option('--max-cycles [maxCycles]', 'maximum measurement cycles per feed').argParser(parseInt))\n .addOption(new Option('--min-cycles [minCycles]', 'minimum measurement cycles per feed').argParser(parseInt))\n .action(async (path, executeOptions) => {\n const files = await glob(path, { absolute: true, cwd: process.cwd() }).catch(() => []);\n for (const file of files) {\n const stats = await stat(file).catch(() => false as const);\n if (stats && stats.isFile()) {\n const content = await readFile(file, 'utf8');\n const code = await transpile(content);\n let instance: Benchmark<unknown> | undefined;\n const benchmark = (...args: Parameters<typeof Benchmark[\"create\"]>) => {\n if (instance) {\n throw new Error('Only one benchmark per file is supported');\n }\n instance = Benchmark.create(...args);\n return instance;\n };\n const script = new SourceTextModule(code, {\n context: createContext({ benchmark }),\n });\n const imports = new Map();\n await script.link(async (specifier: string, referencingModule) => {\n if (imports.has(specifier)) {\n return imports.get(specifier);\n }\n const mod = await import(Module.isBuiltin(specifier) ? specifier : require.resolve(specifier));\n const exportNames = Object.keys(mod);\n const imported = new SyntheticModule(\n exportNames,\n () => {\n exportNames.forEach((key) => imported.setExport(key, mod[key]));\n },\n { identifier: specifier, context: referencingModule.context },\n );\n\n imports.set(specifier, imported);\n return imported;\n });\n await script.evaluate();\n\n if (instance) {\n const reports = await instance.execute(executeOptions);\n switch (executeOptions.format) {\n case 'json': {\n printJSONReports(reports);\n } break;\n case 'pjson': {\n printJSONReports(reports, 2);\n } break;\n case 'table': {\n printTableReports(reports);\n } break;\n default:\n printSimpleReports(reports);\n }\n }\n }\n }\n });\n\ncommander.parse(process.argv);\n\n"],"names":["createRequire","Module","SyntheticModule","createContext","SourceTextModule","stat","readFile","parse","print","Command","Option","glob","Benchmark","printTableReports","printJSONReports","printSimpleReports","DEFAULT_REPORT_TYPES","DEFAULT_WORKERS","REPORT_TYPES","require","url","name","description","version","commander","transpile","code","ast","syntax","dynamicImport","target","output","module","type","jsc","parser","experimental","argument","addOption","choices","default","argParser","parseInt","action","path","executeOptions","files","absolute","cwd","process","catch","file","stats","isFile","content","instance","benchmark","args","Error","create","script","context","imports","Map","link","specifier","referencingModule","has","get","mod","isBuiltin","resolve","exportNames","Object","keys","imported","forEach","key","setExport","identifier","set","evaluate","reports","execute","format","argv"],"mappings":"AAAA,SAASA,aAAa,EAAEC,MAAM,QAAQ,cAAc;AACpD,SAASC,eAAe,EAAEC,aAAa,EAAEC,gBAAgB,QAA4B,UAAU;AAC/F,SAASC,IAAI,EAAEC,QA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S,CAACD,KAAKR,GAAG,CAACQ,IAAI;gBAC/D,GACA;oBAAEE,YAAYd;oBAAWJ,SAASK,kBAAkBL,OAAO;gBAAC;gBAG9DC,QAAQkB,GAAG,CAACf,WAAWU;gBACvB,OAAOA;YACT;YACA,MAAMf,OAAOqB,QAAQ;YAErB,IAAI1B,UAAU;gBACZ,MAAM2B,UAAU,MAAM3B,SAAS4B,OAAO,CAACtC;gBACvC,OAAQA,eAAeuC,MAAM;oBAC3B,KAAK;wBAAQ;4BACXtE,iBAAiBoE;wBACnB;wBAAE;oBACF,KAAK;wBAAS;4BACZpE,iBAAiBoE,SAAS;wBAC5B;wBAAE;oBACF,KAAK;wBAAS;4BACZrE,kBAAkBqE;wBACpB;wBAAE;oBACF;wBACEnE,mBAAmBmE;gBACvB;YACF;QACF;IACF;AACF;AAEF1D,UAAUjB,KAAK,CAAC0C,QAAQoC,IAAI"}
1
+ {"version":3,"sources":["../src/cli.ts"],"sourcesContent":["import { createRequire, Module } from 'node:module';\nimport { SyntheticModule, createContext, SourceTextModule } from 'node:vm';\nimport { stat, readFile } from 'node:fs/promises';\nimport { parse, print } from '@swc/core';\nimport { Command, Option } from 'commander';\nimport { glob } from 'glob';\nimport { Benchmark, printTableReports, printJSONReports, printSimpleReports, DEFAULT_REPORT_TYPES, DEFAULT_WORKERS } from './index.js';\nimport { REPORT_TYPES } from './types.js';\n\nconst require = createRequire(import.meta.url);\nconst { name, description, version } = require('../package.json');\n\nconst commander = new Command();\n\nconst transpile = async (code: string): Promise<string> => {\n const ast = await parse(code, {\n syntax: 'typescript',\n dynamicImport: true,\n target: 'esnext',\n });\n\n const output = await print(ast, {\n module: {\n type: 'es6',\n },\n jsc: {\n target: 'esnext',\n parser: {\n syntax: 'typescript',\n },\n experimental: {},\n },\n });\n return output.code;\n};\n\ncommander\n .name(name)\n .description(description)\n .version(version)\n .argument('<path>', 'glob pattern to find benchmarks')\n .addOption(new Option('-r, --report-types [reportTypes...]', 'statistic types to include in the report').choices(REPORT_TYPES).default(DEFAULT_REPORT_TYPES))\n .addOption(new Option('-w, --workers [workers]', 'number of concurent workers').default(DEFAULT_WORKERS).argParser(parseInt))\n .addOption(new Option('-f, --format [format]', 'output format').default('simple').choices(['simple', 'json', 'pjson', 'table']))\n .addOption(new Option('--abs-threshold [absThreshold]', 'absolute error threshold in nanoseconds').argParser(parseInt))\n .addOption(new Option('--rel-threshold [relThreshold]', 'relative error threshold (fraction between 0 and 1)').argParser(parseInt))\n .addOption(new Option('--warmup-cycles [warmupCycles]', 'number of warmup cycles before measuring').argParser(parseInt))\n .addOption(new Option('--max-cycles [maxCycles]', 'maximum measurement cycles per feed').argParser(parseInt))\n .addOption(new Option('--min-cycles [minCycles]', 'minimum measurement cycles per feed').argParser(parseInt))\n .action(async (path, executeOptions) => {\n const files = await glob(path, { absolute: true, cwd: process.cwd() }).catch(() => []);\n for (const file of files) {\n const stats = await stat(file).catch(() => false as const);\n if (stats && stats.isFile()) {\n const content = await readFile(file, 'utf8');\n const code = await transpile(content);\n let instance: Benchmark<unknown> | undefined;\n const benchmark = (...args: Parameters<(typeof Benchmark)['create']>) => {\n if (instance) {\n throw new Error('Only one benchmark per file is supported');\n }\n instance = Benchmark.create(...args);\n return instance;\n };\n const script = new SourceTextModule(code, {\n context: createContext({ benchmark }),\n });\n const imports = new Map();\n await script.link(async (specifier: string, referencingModule) => {\n if (imports.has(specifier)) {\n return imports.get(specifier);\n }\n const mod = await import(Module.isBuiltin(specifier) ? specifier : require.resolve(specifier));\n const exportNames = Object.keys(mod);\n const imported = new SyntheticModule(\n exportNames,\n () => {\n exportNames.forEach((key) => imported.setExport(key, mod[key]));\n },\n { identifier: specifier, context: referencingModule.context },\n );\n\n imports.set(specifier, imported);\n return imported;\n });\n await script.evaluate();\n\n if (instance) {\n const reports = await instance.execute(executeOptions);\n switch (executeOptions.format) {\n case 'json':\n {\n printJSONReports(reports);\n }\n break;\n case 'pjson':\n {\n printJSONReports(reports, 2);\n }\n break;\n case 'table':\n {\n printTableReports(reports);\n }\n break;\n default:\n printSimpleReports(reports);\n }\n }\n }\n }\n });\n\ncommander.parse(process.argv);\n"],"names":["createRequire","Module","SyntheticModule","createContext","SourceTextModule","stat","readFile","parse","print","Command","Option","glob","Benchmark","printTableReports","printJSONReports","printSimpleReports","DEFAULT_REPORT_TYPES","DEFAULT_WORKERS","REPORT_TYPES","require","url","name","description","version","commander","transpile","code","ast","syntax","dynamicImport","target","output","module","type","jsc","parser","experimental","argument","addOption","choices","default","argParser","parseInt","action","path","executeOptions","files","absolute","cwd","process","catch","file","stats","isFile","content","instance","benchmark","args","Error","create","script","context","imports","Map","link","specifier","referencingModule","has","get","mod","isBuiltin","resolve","exportNames","Object","keys","imported","forEach","key","setExport","identifier","set","evaluate","reports","execute","format","argv"],"mappings":"AAAA,SAASA,aAAa,EAAEC,MAAM,QAAQ,cAAc;AACpD,SAASC,eAAe,EAAEC,aAAa,EAAEC,gBAAgB,QAAQ,UAAU;AAC3E,SAASC,IAAI,EAAEC,QAAQ,QAAQ,mBAAmB;AAClD,SAASC,KAAK,EAAEC,KAAK,QAAQ,YAAY;AACzC,SAASC,OAAO,EAAEC,MAAM,QAAQ,YAAY;AAC5C,SAASC,IAAI,QAAQ,OAAO;AAC5B,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,gBAAgB,EAAEC,kBAAkB,EAAEC,oBAAoB,EAAEC,eAAe,QAAQ,aAAa;AACvI,SAASC,YAAY,QAAQ,aAAa;AAE1C,MAAMC,UAAUnB,cAAc,YAAYoB,GAAG;AAC7C,MAAM,EAAEC,IAAI,EAAEC,WAAW,EAAEC,OAAO,EAAE,GAAGJ,QAAQ;AAE/C,MAAMK,YAAY,IAAIf;AAEtB,MAAMgB,YAAY,OAAOC;IACvB,MAAMC,MAAM,MAAMpB,MAAMmB,MAAM;QAC5BE,QAAQ;QACRC,eAAe;QACfC,QAAQ;IACV;IAEA,MAAMC,SAAS,MAAMvB,MAAMmB,KAAK;QAC9BK,QAAQ;YACNC,MAA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J,MAAMC,YAAY,CAAC,GAAGC;gBACpB,IAAIF,UAAU;oBACZ,MAAM,IAAIG,MAAM;gBAClB;gBACAH,WAAW3C,UAAU+C,MAAM,IAAIF;gBAC/B,OAAOF;YACT;YACA,MAAMK,SAAS,IAAIxD,iBAAiBsB,MAAM;gBACxCmC,SAAS1D,cAAc;oBAAEqD;gBAAU;YACrC;YACA,MAAMM,UAAU,IAAIC;YACpB,MAAMH,OAAOI,IAAI,CAAC,OAAOC,WAAmBC;gBAC1C,IAAIJ,QAAQK,GAAG,CAACF,YAAY;oBAC1B,OAAOH,QAAQM,GAAG,CAACH;gBACrB;gBACA,MAAMI,MAAM,MAAM,MAAM,CAACpE,OAAOqE,SAAS,CAACL,aAAaA,YAAY9C,QAAQoD,OAAO,CAACN;gBACnF,MAAMO,cAAcC,OAAOC,IAAI,CAACL;gBAChC,MAAMM,WAAW,IAAIzE,gBACnBsE,aACA;oBACEA,YAAYI,OAAO,CAAC,CAACC,MAAQF,SAASG,SAAS,CAACD,KAAKR,GAAG,CAACQ,IAAI;gBAC/D,GACA;oBAAEE,YAAYd;oBAAWJ,SAASK,kBAAkBL,OAAO;gBAAC;gBAG9DC,QAAQkB,GAAG,CAACf,WAAWU;gBACvB,OAAOA;YACT;YACA,MAAMf,OAAOqB,QAAQ;YAErB,IAAI1B,UAAU;gBACZ,MAAM2B,UAAU,MAAM3B,SAAS4B,OAAO,CAACtC;gBACvC,OAAQA,eAAeuC,MAAM;oBAC3B,KAAK;wBACH;4BACEtE,iBAAiBoE;wBACnB;wBACA;oBACF,KAAK;wBACH;4BACEpE,iBAAiBoE,SAAS;wBAC5B;wBACA;oBACF,KAAK;wBACH;4BACErE,kBAAkBqE;wBACpB;wBACA;oBACF;wBACEnE,mBAAmBmE;gBACvB;YACF;QACF;IACF;AACF;AAEF1D,UAAUjB,KAAK,CAAC0C,QAAQoC,IAAI"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/executor.ts"],"sourcesContent":["import { Worker } from 'node:worker_threads';\nimport { once } from 'node:events';\nimport { queue } from 'async';\nimport { RunOptions, ReportOptions, WorkerOptions, BenchmarkOptions, Control, ReportType, ReportTypeList, CONTROL_SLOTS } from './types.js';\nimport { createReport, Report } from './reporter.js';\nimport { cmp } from './utils.js';\n\nexport type ExecutorReport<R extends ReportTypeList> =\n Record<R[number], Report> & { count: number };\n\nexport interface ExecutorOptions<R extends ReportTypeList> extends BenchmarkOptions, ReportOptions<R> {\n workers?: number;\n maxCycles?: number;\n}\n\nexport const createExecutor = <TContext, TInput, R extends ReportTypeList>({\n workers,\n warmupCycles,\n maxCycles,\n minCycles,\n absThreshold,\n relThreshold,\n reportTypes,\n}: Required<ExecutorOptions<R>>) => {\n\n const executor = queue<RunOptions<TContext, TInput>>(async ({\n setup,\n teardown,\n pre,\n run,\n post,\n data,\n }) => {\n const setupCode = setup?.toString();\n const teardownCode = teardown?.toString();\n const preCode = pre?.toString();\n const runCode = run.toString()!;\n const postCode = post?.toString();\n\n const controlSAB = new SharedArrayBuffer(\n Int32Array.BYTES_PER_ELEMENT * CONTROL_SLOTS\n );\n const durationsSAB = new SharedArrayBuffer(\n BigUint64Array.BYTES_PER_ELEMENT * maxCycles\n );\n\n const workerFile = new URL('./worker.js', import.meta.url);\n const workerData: WorkerOptions = {\n setupCode,\n teardownCode,\n preCode,\n runCode,\n postCode,\n data,\n\n warmupCycles,\n minCycles,\n absThreshold,\n relThreshold,\n\n controlSAB,\n durationsSAB,\n };\n\n const worker = new Worker(workerFile, {\n workerData,\n });\n const [exitCode] = await once(worker, 'exit');\n if (exitCode !== 0) {\n throw new Error(`worker exited with code ${exitCode}`);\n }\n\n const control = new Int32Array(controlSAB);\n const count = control[Control.INDEX];\n const durations = new BigUint64Array(durationsSAB)\n .slice(0, count)\n .sort(cmp);\n\n const report = reportTypes\n .map<[string, unknown]>((type) => [type, createReport(durations, type)] as [ReportType, Report])\n .concat([['count', count]]);\n return Object.fromEntries(report);\n }, workers);\n\n executor.error((err) => {\n console.error(err);\n });\n\n return executor;\n};\n"],"names":["createExecutor","workers","warmupCycles","maxCycles","minCycles","absThreshold","relThreshold","reportTypes","executor","queue","setup","teardown","pre","run","post","data","setupCode","toString","teardownCode","preCode","runCode","postCode","controlSAB","SharedArrayBuffer","Int32Array","BYTES_PER_ELEMENT","CONTROL_SLOTS","durationsSAB","BigUint64Array","workerFile","URL","workerData","worker","Worker","exitCode","once","Error","control","count","Control","INDEX","durations","slice","sort","cmp","report","map","type","createReport","concat","Object","fromEntries","error","err","console"],"mappings":";;;;+BAeaA;;;eAAAA;;;oCAfU;4BACF;uBACC;0BACyG;6BAC1F;0BACjB;AAUb,MAAMA,iBAAiB,CAA6C,EACzEC,OAAO,EACPC,YAAY,EACZC,SAAS,EACTC,SAAS,EACTC,YAAY,EACZC,YAAY,EACZC,WAAW,EACkB;IAE7B,MAAMC,WAAWC,IAAAA,YAAK,EAA+B,OAAO,EAC1DC,KAAK,EACLC,QAAQ,EACRC,GAAG,EACHC,GAAG,EACHC,IAAI,EACJC,IAAI,EACL;QACC,MAAMC,YAAYN,OAAOO;QACzB,MAAMC,eAAeP,UAAUM;QAC/B,MAAME,UAAUP,KAAKK;QACrB,MAAMG,UAAUP,IAAII,QAAQ;QAC5B,MAAMI,WAAWP,MAAMG;QAEvB,MAAMK,aAAa,IAAIC,kBACrBC,WAAWC,iBAAiB,GAAGC,uBAAa;QAE9C,MAAMC,eAAe,IAAIJ,kBACvBK,eAAeH,iBAAiB,GAAGtB;QAGrC,MAAM0B,aAAa,IAAIC,IAAI,eAAe;QAC1C,MAAMC,aAA4B;YAChCf;YACAE;YACAC;YACAC;YACAC;YACAN;YAEAb;YACAE;YACAC;YACAC;YAEAgB;YACAK;QACF;QAEA,MAAMK,SAAS,IAAIC,0BAAM,CAACJ,YAAY;YACpCE;QACF;QACA,MAAM,CAACG,SAAS,GAAG,MAAMC,IAAAA,gBAAI,EAACH,QAAQ;QACtC,IAAIE,aAAa,GAAG;YAClB,MAAM,IAAIE,MAAM,CAAC,wBAAwB,EAAEF,UAAU;QACvD;QAEA,MAAMG,UAAU,IAAIb,WAAWF;QAC/B,MAAMgB,QAAQD,OAAO,CAACE,iBAAO,CAACC,KAAK,CAAC;QACpC,MAAMC,YAAY,IAAIb,eAAeD,cAClCe,KAAK,CAAC,GAAGJ,OACTK,IAAI,CAACC,aAAG;QAEX,MAAMC,SAAStC,YACZuC,GAAG,CAAoB,CAACC,OAAS;gBAACA;gBAAMC,IAAAA,yBAAY,EAACP,WAAWM;aAAM,EACtEE,MAAM,CAAC;YAAC;gBAAC;gBAASX;aAAM;SAAC;QAC5B,OAAOY,OAAOC,WAAW,CAACN;IAC5B,GAAG5C;IAEHO,SAAS4C,KAAK,CAAC,CAACC;QACdC,QAAQF,KAAK,CAACC;IAChB;IAEA,OAAO7C;AACT"}
1
+ {"version":3,"sources":["../src/executor.ts"],"sourcesContent":["import { Worker } from 'node:worker_threads';\nimport { once } from 'node:events';\nimport { queue } from 'async';\nimport { RunOptions, ReportOptions, WorkerOptions, BenchmarkOptions, Control, ReportType, ReportTypeList, CONTROL_SLOTS } from './types.js';\nimport { createReport, Report } from './reporter.js';\nimport { cmp } from './utils.js';\n\nexport type ExecutorReport<R extends ReportTypeList> = Record<R[number], Report> & { count: number };\n\nexport interface ExecutorOptions<R extends ReportTypeList> extends BenchmarkOptions, ReportOptions<R> {\n workers?: number;\n maxCycles?: number;\n}\n\nexport const createExecutor = <TContext, TInput, R extends ReportTypeList>({\n workers,\n warmupCycles,\n maxCycles,\n minCycles,\n absThreshold,\n relThreshold,\n reportTypes,\n}: Required<ExecutorOptions<R>>) => {\n const executor = queue<RunOptions<TContext, TInput>>(async ({ setup, teardown, pre, run, post, data }) => {\n const setupCode = setup?.toString();\n const teardownCode = teardown?.toString();\n const preCode = pre?.toString();\n const runCode = run.toString()!;\n const postCode = post?.toString();\n\n const controlSAB = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * CONTROL_SLOTS);\n const durationsSAB = new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT * maxCycles);\n\n const workerFile = new URL('./worker.js', import.meta.url);\n const workerData: WorkerOptions = {\n setupCode,\n teardownCode,\n preCode,\n runCode,\n postCode,\n data,\n\n warmupCycles,\n minCycles,\n absThreshold,\n relThreshold,\n\n controlSAB,\n durationsSAB,\n };\n\n const worker = new Worker(workerFile, {\n workerData,\n });\n const [exitCode] = await once(worker, 'exit');\n if (exitCode !== 0) {\n throw new Error(`worker exited with code ${exitCode}`);\n }\n\n const control = new Int32Array(controlSAB);\n const count = control[Control.INDEX];\n const durations = new BigUint64Array(durationsSAB).slice(0, count).sort(cmp);\n\n const report = reportTypes.map<[string, unknown]>((type) => [type, createReport(durations, type)] as [ReportType, Report]).concat([['count', count]]);\n return Object.fromEntries(report);\n }, workers);\n\n executor.error((err) => {\n console.error(err);\n });\n\n return executor;\n};\n"],"names":["createExecutor","workers","warmupCycles","maxCycles","minCycles","absThreshold","relThreshold","reportTypes","executor","queue","setup","teardown","pre","run","post","data","setupCode","toString","teardownCode","preCode","runCode","postCode","controlSAB","SharedArrayBuffer","Int32Array","BYTES_PER_ELEMENT","CONTROL_SLOTS","durationsSAB","BigUint64Array","workerFile","URL","workerData","worker","Worker","exitCode","once","Error","control","count","Control","INDEX","durations","slice","sort","cmp","report","map","type","createReport","concat","Object","fromEntries","error","err","console"],"mappings":";;;;+BAcaA;;;eAAAA;;;oCAdU;4BACF;uBACC;0BACyG;6BAC1F;0BACjB;AASb,MAAMA,iBAAiB,CAA6C,EACzEC,OAAO,EACPC,YAAY,EACZC,SAAS,EACTC,SAAS,EACTC,YAAY,EACZC,YAAY,EACZC,WAAW,EACkB;IAC7B,MAAMC,WAAWC,IAAAA,YAAK,EAA+B,OAAO,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAE;QACnG,MAAMC,YAAYN,OAAOO;QACzB,MAAMC,eAAeP,UAAUM;QAC/B,MAAME,UAAUP,KAAKK;QACrB,MAAMG,UAAUP,IAAII,QAAQ;QAC5B,MAAMI,WAAWP,MAAMG;QAEvB,MAAMK,aAAa,IAAIC,kBAAkBC,WAAWC,iBAAiB,GAAGC,uBAAa;QACrF,MAAMC,eAAe,IAAIJ,kBAAkBK,eAAeH,iBAAiB,GAAGtB;QAE9E,MAAM0B,aAAa,IAAIC,IAAI,eAAe;QAC1C,MAAMC,aAA4B;YAChCf;YACAE;YACAC;YACAC;YACAC;YACAN;YAEAb;YACAE;YACAC;YACAC;YAEAgB;YACAK;QACF;QAEA,MAAMK,SAAS,IAAIC,0BAAM,CAACJ,YAAY;YACpCE;QACF;QACA,MAAM,CAACG,SAAS,GAAG,MAAMC,IAAAA,gBAAI,EAACH,QAAQ;QACtC,IAAIE,aAAa,GAAG;YAClB,MAAM,IAAIE,MAAM,CAAC,wBAAwB,EAAEF,UAAU;QACvD;QAEA,MAAMG,UAAU,IAAIb,WAAWF;QAC/B,MAAMgB,QAAQD,OAAO,CAACE,iBAAO,CAACC,KAAK,CAAC;QACpC,MAAMC,YAAY,IAAIb,eAAeD,cAAce,KAAK,CAAC,GAAGJ,OAAOK,IAAI,CAACC,aAAG;QAE3E,MAAMC,SAAStC,YAAYuC,GAAG,CAAoB,CAACC,OAAS;gBAACA;gBAAMC,IAAAA,yBAAY,EAACP,WAAWM;aAAM,EAA0BE,MAAM,CAAC;YAAC;gBAAC;gBAASX;aAAM;SAAC;QACpJ,OAAOY,OAAOC,WAAW,CAACN;IAC5B,GAAG5C;IAEHO,SAAS4C,KAAK,CAAC,CAACC;QACdC,QAAQF,KAAK,CAACC;IAChB;IAEA,OAAO7C;AACT"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/executor.ts"],"sourcesContent":["import { Worker } from 'node:worker_threads';\nimport { once } from 'node:events';\nimport { queue } from 'async';\nimport { RunOptions, ReportOptions, WorkerOptions, BenchmarkOptions, Control, ReportType, ReportTypeList, CONTROL_SLOTS } from './types.js';\nimport { createReport, Report } from './reporter.js';\nimport { cmp } from './utils.js';\n\nexport type ExecutorReport<R extends ReportTypeList> =\n Record<R[number], Report> & { count: number };\n\nexport interface ExecutorOptions<R extends ReportTypeList> extends BenchmarkOptions, ReportOptions<R> {\n workers?: number;\n maxCycles?: number;\n}\n\nexport const createExecutor = <TContext, TInput, R extends ReportTypeList>({\n workers,\n warmupCycles,\n maxCycles,\n minCycles,\n absThreshold,\n relThreshold,\n reportTypes,\n}: Required<ExecutorOptions<R>>) => {\n\n const executor = queue<RunOptions<TContext, TInput>>(async ({\n setup,\n teardown,\n pre,\n run,\n post,\n data,\n }) => {\n const setupCode = setup?.toString();\n const teardownCode = teardown?.toString();\n const preCode = pre?.toString();\n const runCode = run.toString()!;\n const postCode = post?.toString();\n\n const controlSAB = new SharedArrayBuffer(\n Int32Array.BYTES_PER_ELEMENT * CONTROL_SLOTS\n );\n const durationsSAB = new SharedArrayBuffer(\n BigUint64Array.BYTES_PER_ELEMENT * maxCycles\n );\n\n const workerFile = new URL('./worker.js', import.meta.url);\n const workerData: WorkerOptions = {\n setupCode,\n teardownCode,\n preCode,\n runCode,\n postCode,\n data,\n\n warmupCycles,\n minCycles,\n absThreshold,\n relThreshold,\n\n controlSAB,\n durationsSAB,\n };\n\n const worker = new Worker(workerFile, {\n workerData,\n });\n const [exitCode] = await once(worker, 'exit');\n if (exitCode !== 0) {\n throw new Error(`worker exited with code ${exitCode}`);\n }\n\n const control = new Int32Array(controlSAB);\n const count = control[Control.INDEX];\n const durations = new BigUint64Array(durationsSAB)\n .slice(0, count)\n .sort(cmp);\n\n const report = reportTypes\n .map<[string, unknown]>((type) => [type, createReport(durations, type)] as [ReportType, Report])\n .concat([['count', count]]);\n return Object.fromEntries(report);\n }, workers);\n\n executor.error((err) => {\n console.error(err);\n });\n\n return executor;\n};\n"],"names":["Worker","once","queue","Control","CONTROL_SLOTS","createReport","cmp","createExecutor","workers","warmupCycles","maxCycles","minCycles","absThreshold","relThreshold","reportTypes","executor","setup","teardown","pre","run","post","data","setupCode","toString","teardownCode","preCode","runCode","postCode","controlSAB","SharedArrayBuffer","Int32Array","BYTES_PER_ELEMENT","durationsSAB","BigUint64Array","workerFile","URL","url","workerData","worker","exitCode","Error","control","count","INDEX","durations","slice","sort","report","map","type","concat","Object","fromEntries","error","err","console"],"mappings":"AAAA,SAASA,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,IAAI,QAAQ,cAAc;AACnC,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SAAqEC,OAAO,EAA8BC,aAAa,QAAQ,aAAa;AAC5I,SAASC,YAAY,QAAgB,gBAAgB;AACrD,SAASC,GAAG,QAAQ,aAAa;AAUjC,OAAO,MAAMC,iBAAiB,CAA6C,EACzEC,OAAO,EACPC,YAAY,EACZC,SAAS,EACTC,SAAS,EACTC,YAAY,EACZC,YAAY,EACZC,WAAW,EACkB;IAE7B,MAAMC,WAAWb,MAAoC,OAAO,EAC1Dc,KAAK,EACLC,QAAQ,EACRC,GAAG,EACHC,GAAG,EACHC,IAAI,EACJC,IAAI,EACL;QACC,MAAMC,YAAYN,OAAOO;QACzB,MAAMC,eAAeP,UAAUM;QAC/B,MAAME,UAAUP,KAAKK;QACrB,MAAMG,UAAUP,IAAII,QAAQ;QAC5B,MAAMI,WAAWP,MAAMG;QAEvB,MAAMK,aAAa,IAAIC,kBACrBC,WAAWC,iBAAiB,GAAG3B;QAEjC,MAAM4B,eAAe,IAAIH,kBACvBI,eAAeF,iBAAiB,GAAGrB;QAGrC,MAAMwB,aAAa,IAAIC,IAAI,eAAe,YAAYC,GAAG;QACzD,MAAMC,aAA4B;YAChCf;YACAE;YACAC;YACAC;YACAC;YACAN;YAEAZ;YACAE;YACAC;YACAC;YAEAe;YACAI;QACF;QAEA,MAAMM,SAAS,IAAItC,OAAOkC,YAAY;YACpCG;QACF;QACA,MAAM,CAACE,SAAS,GAAG,MAAMtC,KAAKqC,QAAQ;QACtC,IAAIC,aAAa,GAAG;YAClB,MAAM,IAAIC,MAAM,CAAC,wBAAwB,EAAED,UAAU;QACvD;QAEA,MAAME,UAAU,IAAIX,WAAWF;QAC/B,MAAMc,QAAQD,OAAO,CAACtC,QAAQwC,KAAK,CAAC;QACpC,MAAMC,YAAY,IAAIX,eAAeD,cAClCa,KAAK,CAAC,GAAGH,OACTI,IAAI,CAACxC;QAER,MAAMyC,SAASjC,YACZkC,GAAG,CAAoB,CAACC,OAAS;gBAACA;gBAAM5C,aAAauC,WAAWK;aAAM,EACtEC,MAAM,CAAC;YAAC;gBAAC;gBAASR;aAAM;SAAC;QAC5B,OAAOS,OAAOC,WAAW,CAACL;IAC5B,GAAGvC;IAEHO,SAASsC,KAAK,CAAC,CAACC;QACdC,QAAQF,KAAK,CAACC;IAChB;IAEA,OAAOvC;AACT,EAAE"}
1
+ {"version":3,"sources":["../src/executor.ts"],"sourcesContent":["import { Worker } from 'node:worker_threads';\nimport { once } from 'node:events';\nimport { queue } from 'async';\nimport { RunOptions, ReportOptions, WorkerOptions, BenchmarkOptions, Control, ReportType, ReportTypeList, CONTROL_SLOTS } from './types.js';\nimport { createReport, Report } from './reporter.js';\nimport { cmp } from './utils.js';\n\nexport type ExecutorReport<R extends ReportTypeList> = Record<R[number], Report> & { count: number };\n\nexport interface ExecutorOptions<R extends ReportTypeList> extends BenchmarkOptions, ReportOptions<R> {\n workers?: number;\n maxCycles?: number;\n}\n\nexport const createExecutor = <TContext, TInput, R extends ReportTypeList>({\n workers,\n warmupCycles,\n maxCycles,\n minCycles,\n absThreshold,\n relThreshold,\n reportTypes,\n}: Required<ExecutorOptions<R>>) => {\n const executor = queue<RunOptions<TContext, TInput>>(async ({ setup, teardown, pre, run, post, data }) => {\n const setupCode = setup?.toString();\n const teardownCode = teardown?.toString();\n const preCode = pre?.toString();\n const runCode = run.toString()!;\n const postCode = post?.toString();\n\n const controlSAB = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * CONTROL_SLOTS);\n const durationsSAB = new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT * maxCycles);\n\n const workerFile = new URL('./worker.js', import.meta.url);\n const workerData: WorkerOptions = {\n setupCode,\n teardownCode,\n preCode,\n runCode,\n postCode,\n data,\n\n warmupCycles,\n minCycles,\n absThreshold,\n relThreshold,\n\n controlSAB,\n durationsSAB,\n };\n\n const worker = new Worker(workerFile, {\n workerData,\n });\n const [exitCode] = await once(worker, 'exit');\n if (exitCode !== 0) {\n throw new Error(`worker exited with code ${exitCode}`);\n }\n\n const control = new Int32Array(controlSAB);\n const count = control[Control.INDEX];\n const durations = new BigUint64Array(durationsSAB).slice(0, count).sort(cmp);\n\n const report = reportTypes.map<[string, unknown]>((type) => [type, createReport(durations, type)] as [ReportType, Report]).concat([['count', count]]);\n return Object.fromEntries(report);\n }, workers);\n\n executor.error((err) => {\n console.error(err);\n });\n\n return executor;\n};\n"],"names":["Worker","once","queue","Control","CONTROL_SLOTS","createReport","cmp","createExecutor","workers","warmupCycles","maxCycles","minCycles","absThreshold","relThreshold","reportTypes","executor","setup","teardown","pre","run","post","data","setupCode","toString","teardownCode","preCode","runCode","postCode","controlSAB","SharedArrayBuffer","Int32Array","BYTES_PER_ELEMENT","durationsSAB","BigUint64Array","workerFile","URL","url","workerData","worker","exitCode","Error","control","count","INDEX","durations","slice","sort","report","map","type","concat","Object","fromEntries","error","err","console"],"mappings":"AAAA,SAASA,MAAM,QAAQ,sBAAsB;AAC7C,SAASC,IAAI,QAAQ,cAAc;AACnC,SAASC,KAAK,QAAQ,QAAQ;AAC9B,SAAqEC,OAAO,EAA8BC,aAAa,QAAQ,aAAa;AAC5I,SAASC,YAAY,QAAgB,gBAAgB;AACrD,SAASC,GAAG,QAAQ,aAAa;AASjC,OAAO,MAAMC,iBAAiB,CAA6C,EACzEC,OAAO,EACPC,YAAY,EACZC,SAAS,EACTC,SAAS,EACTC,YAAY,EACZC,YAAY,EACZC,WAAW,EACkB;IAC7B,MAAMC,WAAWb,MAAoC,OAAO,EAAEc,KAAK,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAE;QACnG,MAAMC,YAAYN,OAAOO;QACzB,MAAMC,eAAeP,UAAUM;QAC/B,MAAME,UAAUP,KAAKK;QACrB,MAAMG,UAAUP,IAAII,QAAQ;QAC5B,MAAMI,WAAWP,MAAMG;QAEvB,MAAMK,aAAa,IAAIC,kBAAkBC,WAAWC,iBAAiB,GAAG3B;QACxE,MAAM4B,eAAe,IAAIH,kBAAkBI,eAAeF,iBAAiB,GAAGrB;QAE9E,MAAMwB,aAAa,IAAIC,IAAI,eAAe,YAAYC,GAAG;QACzD,MAAMC,aAA4B;YAChCf;YACAE;YACAC;YACAC;YACAC;YACAN;YAEAZ;YACAE;YACAC;YACAC;YAEAe;YACAI;QACF;QAEA,MAAMM,SAAS,IAAItC,OAAOkC,YAAY;YACpCG;QACF;QACA,MAAM,CAACE,SAAS,GAAG,MAAMtC,KAAKqC,QAAQ;QACtC,IAAIC,aAAa,GAAG;YAClB,MAAM,IAAIC,MAAM,CAAC,wBAAwB,EAAED,UAAU;QACvD;QAEA,MAAME,UAAU,IAAIX,WAAWF;QAC/B,MAAMc,QAAQD,OAAO,CAACtC,QAAQwC,KAAK,CAAC;QACpC,MAAMC,YAAY,IAAIX,eAAeD,cAAca,KAAK,CAAC,GAAGH,OAAOI,IAAI,CAACxC;QAExE,MAAMyC,SAASjC,YAAYkC,GAAG,CAAoB,CAACC,OAAS;gBAACA;gBAAM5C,aAAauC,WAAWK;aAAM,EAA0BC,MAAM,CAAC;YAAC;gBAAC;gBAASR;aAAM;SAAC;QACpJ,OAAOS,OAAOC,WAAW,CAACL;IAC5B,GAAGvC;IAEHO,SAASsC,KAAK,CAAC,CAACC;QACdC,QAAQF,KAAK,CAACC;IAChB;IAEA,OAAOvC;AACT,EAAE"}
package/build/index.cjs CHANGED
@@ -2,19 +2,236 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- _export_star(require("./benchmark.cjs"), exports);
6
- function _export_star(from, to) {
7
- Object.keys(from).forEach(function(k) {
8
- if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
9
- Object.defineProperty(to, k, {
10
- enumerable: true,
11
- get: function() {
12
- return from[k];
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ AsyncFunction: function() {
13
+ return AsyncFunction;
14
+ },
15
+ Benchmark: function() {
16
+ return Benchmark;
17
+ },
18
+ DEFAULT_REPORT_TYPES: function() {
19
+ return DEFAULT_REPORT_TYPES;
20
+ },
21
+ DEFAULT_WORKERS: function() {
22
+ return DEFAULT_WORKERS;
23
+ },
24
+ FeedContext: function() {
25
+ return FeedContext;
26
+ },
27
+ Measure: function() {
28
+ return Measure;
29
+ },
30
+ MeasureContext: function() {
31
+ return MeasureContext;
32
+ },
33
+ Target: function() {
34
+ return Target;
35
+ },
36
+ TargetContext: function() {
37
+ return TargetContext;
38
+ },
39
+ printJSONReports: function() {
40
+ return printJSONReports;
41
+ },
42
+ printSimpleReports: function() {
43
+ return printSimpleReports;
44
+ },
45
+ printTableReports: function() {
46
+ return printTableReports;
47
+ }
48
+ });
49
+ const _nodeos = require("node:os");
50
+ const _executorcjs = require("./executor.cjs");
51
+ const _typescjs = require("./types.cjs");
52
+ const DEFAULT_WORKERS = (0, _nodeos.cpus)().length;
53
+ const AsyncFunction = (async ()=>{}).constructor;
54
+ const DEFAULT_REPORT_TYPES = [
55
+ 'ops'
56
+ ];
57
+ class MeasureContext {
58
+ title;
59
+ run;
60
+ pre;
61
+ post;
62
+ constructor(title, run){
63
+ this.title = title;
64
+ this.run = run;
65
+ }
66
+ }
67
+ class Measure {
68
+ #ctx;
69
+ constructor(ctx){
70
+ this.#ctx = ctx;
71
+ }
72
+ pre(fn) {
73
+ this.#ctx.pre = fn;
74
+ return this;
75
+ }
76
+ post(fn) {
77
+ this.#ctx.post = fn;
78
+ return this;
79
+ }
80
+ }
81
+ class TargetContext {
82
+ title;
83
+ setup;
84
+ teardown;
85
+ measures;
86
+ constructor(title, setup){
87
+ this.title = title;
88
+ this.setup = setup;
89
+ this.measures = [];
90
+ }
91
+ }
92
+ class Target {
93
+ #ctx;
94
+ constructor(ctx){
95
+ this.#ctx = ctx;
96
+ }
97
+ teardown(fn) {
98
+ this.#ctx.teardown = fn;
99
+ return this;
100
+ }
101
+ measure(title, run) {
102
+ const measure = new MeasureContext(title, run);
103
+ this.#ctx.measures.push(measure);
104
+ return new Measure(measure);
105
+ }
106
+ }
107
+ class FeedContext {
108
+ title;
109
+ fn;
110
+ constructor(title, fn){
111
+ this.title = title;
112
+ this.fn = fn;
113
+ }
114
+ }
115
+ class Benchmark {
116
+ #targets = [];
117
+ #feeds = [];
118
+ #executed = false;
119
+ static create(title, fn) {
120
+ if (fn) {
121
+ return new Benchmark(title, fn);
122
+ } else {
123
+ return new Benchmark(title);
124
+ }
125
+ }
126
+ constructor(title, fn){
127
+ if (fn) {
128
+ this.feed(title, fn);
129
+ } else {
130
+ this.feed(title);
131
+ }
132
+ }
133
+ feed(title, fn) {
134
+ const self = this;
135
+ self.#feeds.push(fn ? new FeedContext(title, fn) : new FeedContext(title));
136
+ return self;
137
+ }
138
+ target(title, setup) {
139
+ const target = new TargetContext(title, setup);
140
+ this.#targets.push(target);
141
+ return new Target(target);
142
+ }
143
+ async execute({ workers = DEFAULT_WORKERS, warmupCycles = 20, maxCycles = _typescjs.DEFAULT_CYCLES, minCycles = 50, absThreshold = 1_000, relThreshold = 0.02, reportTypes = DEFAULT_REPORT_TYPES }) {
144
+ if (this.#executed) {
145
+ throw new Error("Benchmark is executed and can't be reused");
146
+ }
147
+ this.#executed = true;
148
+ const executor = (0, _executorcjs.createExecutor)({
149
+ workers,
150
+ warmupCycles,
151
+ maxCycles,
152
+ minCycles,
153
+ absThreshold,
154
+ relThreshold,
155
+ reportTypes
156
+ });
157
+ const reports = [];
158
+ for (const target of this.#targets){
159
+ const targetReport = {
160
+ target: target.title,
161
+ measures: []
162
+ };
163
+ for (const measure of target.measures){
164
+ const measureReport = {
165
+ measure: measure.title,
166
+ feeds: []
167
+ };
168
+ for (const feed of this.#feeds){
169
+ const data = await feed.fn?.();
170
+ executor.push({
171
+ setup: target.setup,
172
+ teardown: target.teardown,
173
+ pre: measure.pre,
174
+ run: measure.run,
175
+ post: measure.post,
176
+ data
177
+ }).then((data)=>{
178
+ measureReport.feeds.push({
179
+ feed: feed.title,
180
+ data
181
+ });
182
+ });
13
183
  }
14
- });
184
+ targetReport.measures.push(measureReport);
185
+ }
186
+ reports.push(targetReport);
15
187
  }
16
- });
17
- return from;
188
+ await executor.drain();
189
+ executor.kill();
190
+ return reports;
191
+ }
18
192
  }
193
+ const printSimpleReports = (reports)=>{
194
+ for (const report of reports){
195
+ for (const { measure, feeds } of report.measures){
196
+ console.group('\n', report.target, measure);
197
+ for (const { feed, data } of feeds){
198
+ const output = Object.entries(data).map(([key, report])=>`${key}: ${report.toString()}`).join('; ');
199
+ console.log(feed, output);
200
+ }
201
+ console.groupEnd();
202
+ }
203
+ }
204
+ };
205
+ const printTableReports = (reports)=>{
206
+ for (const report of reports){
207
+ for (const { measure, feeds } of report.measures){
208
+ console.log('\n', report.target, measure);
209
+ const table = {};
210
+ for (const { feed, data } of feeds){
211
+ table[feed] = Object.fromEntries(Object.entries(data).map(([key, report])=>[
212
+ key,
213
+ report.toString()
214
+ ]));
215
+ }
216
+ console.table(table);
217
+ }
218
+ }
219
+ };
220
+ const printJSONReports = (reports, padding)=>{
221
+ const output = {};
222
+ for (const report of reports){
223
+ for (const { measure, feeds } of report.measures){
224
+ const row = {};
225
+ for (const { feed, data } of feeds){
226
+ row[feed] = Object.fromEntries(Object.entries(data).map(([key, report])=>[
227
+ key,
228
+ report.toString()
229
+ ]));
230
+ }
231
+ output[`${report.target} ${measure}`] = row;
232
+ }
233
+ }
234
+ console.log(JSON.stringify(output, null, padding));
235
+ };
19
236
 
20
237
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './benchmark.js'\nimport { Benchmark as _Benchmark } from './benchmark.js';\n\ndeclare global {\n const benchmark: typeof _Benchmark[\"create\"];\n}\n"],"names":[],"mappings":";;;;qBAAc"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { cpus } from 'node:os';\nimport { createExecutor, ExecutorOptions, ExecutorReport } from './executor.js';\nimport { MaybePromise, StepFn, SetupFn, TeardownFn, FeedFn, ReportType, ReportTypeList, DEFAULT_CYCLES } from './types.js';\n\ndeclare global {\n const benchmark: typeof Benchmark.create;\n}\n\nexport const DEFAULT_WORKERS = cpus().length;\n\nexport const AsyncFunction = (async () => {}).constructor;\n\nexport interface TargetReport<R extends ReportTypeList> {\n target: string;\n measures: MeasureReport<R>[];\n}\n\nexport interface MeasureReport<R extends ReportTypeList> {\n measure: string;\n feeds: FeedReport<R>[];\n}\n\nexport interface FeedReport<R extends ReportTypeList> {\n feed: string;\n data: ExecutorReport<R>;\n}\n\nexport const DEFAULT_REPORT_TYPES = ['ops'] as const;\nexport type DefaultReportTypes = (typeof DEFAULT_REPORT_TYPES)[number];\n\nexport class MeasureContext<TContext, TInput> {\n public pre?: StepFn<TContext, TInput>;\n public post?: StepFn<TContext, TInput>;\n\n constructor(\n public title: string,\n public run: StepFn<TContext, TInput>,\n ) {}\n}\n\nexport class Measure<TContext, TInput> {\n #ctx: MeasureContext<TContext, TInput>;\n\n constructor(ctx: MeasureContext<TContext, TInput>) {\n this.#ctx = ctx;\n }\n\n pre(fn: StepFn<TContext, TInput>): Measure<TContext, TInput> {\n this.#ctx.pre = fn;\n return this;\n }\n post(fn: StepFn<TContext, TInput>): Measure<TContext, TInput> {\n this.#ctx.post = fn;\n return this;\n }\n}\n\nexport class TargetContext<TContext, TInput> {\n public teardown?: TeardownFn<TContext>;\n public measures: MeasureContext<TContext, TInput>[] = [];\n\n constructor(\n readonly title: string,\n readonly setup?: SetupFn<MaybePromise<TContext>>,\n ) {}\n}\n\nexport class Target<TContext, TInput> {\n #ctx: TargetContext<TContext, TInput>;\n\n constructor(ctx: TargetContext<TContext, TInput>) {\n this.#ctx = ctx;\n }\n teardown(fn: TeardownFn<TContext>): Target<TContext, TInput> {\n this.#ctx.teardown = fn;\n\n return this;\n }\n measure(title: string, run: StepFn<TContext, TInput>): Measure<TContext, TInput> {\n const measure = new MeasureContext(title, run);\n this.#ctx.measures.push(measure);\n\n return new Measure(measure);\n }\n}\n\nexport class FeedContext<TInput> {\n constructor(\n readonly title: string,\n readonly fn?: FeedFn<TInput>,\n ) {}\n}\n\nexport class Benchmark<TInput> {\n #targets: TargetContext<unknown, TInput>[] = [];\n #feeds: FeedContext<TInput>[] = [];\n #executed = false;\n\n static create(title: string): Benchmark<void>;\n static create<I>(title: string, fn: FeedFn<I>): Benchmark<I>;\n static create<I>(title: string, fn?: FeedFn<I> | undefined): Benchmark<I> {\n if (fn) {\n return new Benchmark(title, fn);\n } else {\n return new Benchmark(title);\n }\n }\n\n constructor(title: string);\n constructor(title: string, fn: FeedFn<TInput>);\n constructor(title: string, fn?: FeedFn<TInput> | undefined) {\n if (fn) {\n this.feed(title, fn);\n } else {\n this.feed(title);\n }\n }\n\n feed(title: string): Benchmark<TInput | void>;\n feed<I>(title: string, fn: FeedFn<I>): Benchmark<TInput | I>;\n feed<I>(title: string, fn?: FeedFn<I> | undefined): Benchmark<TInput | I> {\n const self = this as Benchmark<TInput | I>;\n self.#feeds.push(fn ? new FeedContext(title, fn) : new FeedContext(title));\n\n return self;\n }\n\n target<TContext>(title: string): Target<void, TInput>;\n target<TContext>(title: string, setup: SetupFn<Awaited<TContext>>): Target<TContext, TInput>;\n target<TContext>(title: string, setup?: SetupFn<Awaited<TContext>> | undefined): Target<TContext, TInput> {\n const target = new TargetContext<TContext, TInput>(title, setup);\n this.#targets.push(target as TargetContext<unknown, TInput>);\n\n return new Target<TContext, TInput>(target);\n }\n\n async execute<R extends readonly ReportType[] = typeof DEFAULT_REPORT_TYPES>({\n workers = DEFAULT_WORKERS,\n warmupCycles = 20,\n maxCycles = DEFAULT_CYCLES,\n minCycles = 50,\n absThreshold = 1_000,\n relThreshold = 0.02,\n reportTypes = DEFAULT_REPORT_TYPES as unknown as R,\n }: ExecutorOptions<R>): Promise<TargetReport<R>[]> {\n if (this.#executed) {\n throw new Error(\"Benchmark is executed and can't be reused\");\n }\n this.#executed = true;\n\n const executor = createExecutor<unknown, TInput, R>({\n workers,\n warmupCycles,\n maxCycles,\n minCycles,\n absThreshold,\n relThreshold,\n reportTypes,\n });\n\n const reports: TargetReport<R>[] = [];\n for (const target of this.#targets) {\n const targetReport: TargetReport<R> = { target: target.title, measures: [] };\n for (const measure of target.measures) {\n const measureReport: MeasureReport<R> = { measure: measure.title, feeds: [] };\n for (const feed of this.#feeds) {\n const data = await feed.fn?.();\n executor\n .push<ExecutorReport<R>>({\n setup: target.setup,\n teardown: target.teardown,\n pre: measure.pre,\n run: measure.run,\n post: measure.post,\n data,\n })\n .then((data) => {\n measureReport.feeds.push({\n feed: feed.title,\n data,\n });\n });\n }\n targetReport.measures.push(measureReport);\n }\n reports.push(targetReport);\n }\n await executor.drain();\n executor.kill();\n\n return reports;\n }\n}\n\nexport const printSimpleReports = <R extends ReportTypeList>(reports: TargetReport<R>[]) => {\n for (const report of reports) {\n for (const { measure, feeds } of report.measures) {\n console.group('\\n', report.target, measure);\n for (const { feed, data } of feeds) {\n const output = Object.entries(data)\n .map(([key, report]) => `${key}: ${report.toString()}`)\n .join('; ');\n console.log(feed, output);\n }\n console.groupEnd();\n }\n }\n};\n\nexport const printTableReports = <R extends ReportTypeList>(reports: TargetReport<R>[]) => {\n for (const report of reports) {\n for (const { measure, feeds } of report.measures) {\n console.log('\\n', report.target, measure);\n const table: Record<string, unknown> = {};\n for (const { feed, data } of feeds) {\n table[feed] = Object.fromEntries(Object.entries(data).map(([key, report]) => [key, report.toString()]));\n }\n console.table(table);\n }\n }\n};\n\nexport const printJSONReports = <R extends ReportTypeList>(reports: TargetReport<R>[], padding?: number) => {\n const output = {} as Record<string, Record<string, Record<string, string>>>;\n for (const report of reports) {\n for (const { measure, feeds } of report.measures) {\n const row = {} as Record<string, Record<string, string>>;\n for (const { feed, data } of feeds) {\n row[feed] = Object.fromEntries(Object.entries(data).map(([key, report]) => [key, report.toString()]));\n }\n output[`${report.target} ${measure}`] = row;\n }\n }\n console.log(JSON.stringify(output, null, padding));\n};\n"],"names":["AsyncFunction","Benchmark","DEFAULT_REPORT_TYPES","DEFAULT_WORKERS","FeedContext","Measure","MeasureContext","Target","TargetContext","printJSONReports","printSimpleReports","printTableReports","cpus","length","constructor","pre","post","title","run","ctx","fn","teardown","measures","setup","measure","push","create","feed","self","target","execute","workers","warmupCycles","maxCycles","DEFAULT_CYCLES","minCycles","absThreshold","relThreshold","reportTypes","Error","executor","createExecutor","reports","targetReport","measureReport","feeds","data","then","drain","kill","report","console","group","output","Object","entries","map","key","toString","join","log","groupEnd","table","fromEntries","padding","row","JSON","stringify"],"mappings":";;;;;;;;;;;IAUaA,aAAa;eAAbA;;IAmFAC,SAAS;eAATA;;IAlEAC,oBAAoB;eAApBA;;IAnBAC,eAAe;eAAfA;;IA8EAC,WAAW;eAAXA;;IA9CAC,OAAO;eAAPA;;IAVAC,cAAc;eAAdA;;IAqCAC,MAAM;eAANA;;IAVAC,aAAa;eAAbA;;IAqKAC,gBAAgB;eAAhBA;;IA5BAC,kBAAkB;eAAlBA;;IAeAC,iBAAiB;eAAjBA;;;wBAjNQ;6BAC2C;0BAC8C;AAMvG,MAAMR,kBAAkBS,IAAAA,YAAI,IAAGC,MAAM;AAErC,MAAMb,gBAAgB,AAAC,CAAA,WAAa,CAAA,EAAGc,WAAW;AAiBlD,MAAMZ,uBAAuB;IAAC;CAAM;AAGpC,MAAMI;;;IACJS,IAA+B;IAC/BC,KAAgC;IAEvCF,YACE,AAAOG,KAAa,EACpB,AAAOC,GAA6B,CACpC;aAFOD,Q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,CAAC,MAAMV,OAAOrB,MAAM,EAAEL;YACjC,MAAMsC,QAAiC,CAAC;YACxC,KAAK,MAAM,EAAEnC,IAAI,EAAEmB,IAAI,EAAE,IAAID,MAAO;gBAClCiB,KAAK,CAACnC,KAAK,GAAG2B,OAAOS,WAAW,CAACT,OAAOC,OAAO,CAACT,MAAMU,GAAG,CAAC,CAAC,CAACC,KAAKP,OAAO,GAAK;wBAACO;wBAAKP,OAAOQ,QAAQ;qBAAG;YACvG;YACAP,QAAQW,KAAK,CAACA;QAChB;IACF;AACF;AAEO,MAAMrD,mBAAmB,CAA2BiC,SAA4BsB;IACrF,MAAMX,SAAS,CAAC;IAChB,KAAK,MAAMH,UAAUR,QAAS;QAC5B,KAAK,MAAM,EAAElB,OAAO,EAAEqB,KAAK,EAAE,IAAIK,OAAO5B,QAAQ,CAAE;YAChD,MAAM2C,MAAM,CAAC;YACb,KAAK,MAAM,EAAEtC,IAAI,EAAEmB,IAAI,EAAE,IAAID,MAAO;gBAClCoB,GAAG,CAACtC,KAAK,GAAG2B,OAAOS,WAAW,CAACT,OAAOC,OAAO,CAACT,MAAMU,GAAG,CAAC,CAAC,CAACC,KAAKP,OAAO,GAAK;wBAACO;wBAAKP,OAAOQ,QAAQ;qBAAG;YACrG;YACAL,MAAM,CAAC,GAAGH,OAAOrB,MAAM,CAAC,CAAC,EAAEL,SAAS,CAAC,GAAGyC;QAC1C;IACF;IACAd,QAAQS,GAAG,CAACM,KAAKC,SAAS,CAACd,QAAQ,MAAMW;AAC3C"}
package/build/index.d.ts CHANGED
@@ -1,5 +1,67 @@
1
- export * from './benchmark.js';
2
- import { Benchmark as _Benchmark } from './benchmark.js';
1
+ import { ExecutorOptions, ExecutorReport } from './executor.js';
2
+ import { MaybePromise, StepFn, SetupFn, TeardownFn, FeedFn, ReportType, ReportTypeList } from './types.js';
3
3
  declare global {
4
- const benchmark: typeof _Benchmark["create"];
4
+ const benchmark: typeof Benchmark.create;
5
5
  }
6
+ export declare const DEFAULT_WORKERS: number;
7
+ export declare const AsyncFunction: Function;
8
+ export interface TargetReport<R extends ReportTypeList> {
9
+ target: string;
10
+ measures: MeasureReport<R>[];
11
+ }
12
+ export interface MeasureReport<R extends ReportTypeList> {
13
+ measure: string;
14
+ feeds: FeedReport<R>[];
15
+ }
16
+ export interface FeedReport<R extends ReportTypeList> {
17
+ feed: string;
18
+ data: ExecutorReport<R>;
19
+ }
20
+ export declare const DEFAULT_REPORT_TYPES: readonly ["ops"];
21
+ export type DefaultReportTypes = (typeof DEFAULT_REPORT_TYPES)[number];
22
+ export declare class MeasureContext<TContext, TInput> {
23
+ title: string;
24
+ run: StepFn<TContext, TInput>;
25
+ pre?: StepFn<TContext, TInput>;
26
+ post?: StepFn<TContext, TInput>;
27
+ constructor(title: string, run: StepFn<TContext, TInput>);
28
+ }
29
+ export declare class Measure<TContext, TInput> {
30
+ #private;
31
+ constructor(ctx: MeasureContext<TContext, TInput>);
32
+ pre(fn: StepFn<TContext, TInput>): Measure<TContext, TInput>;
33
+ post(fn: StepFn<TContext, TInput>): Measure<TContext, TInput>;
34
+ }
35
+ export declare class TargetContext<TContext, TInput> {
36
+ readonly title: string;
37
+ readonly setup?: SetupFn<MaybePromise<TContext>> | undefined;
38
+ teardown?: TeardownFn<TContext>;
39
+ measures: MeasureContext<TContext, TInput>[];
40
+ constructor(title: string, setup?: SetupFn<MaybePromise<TContext>> | undefined);
41
+ }
42
+ export declare class Target<TContext, TInput> {
43
+ #private;
44
+ constructor(ctx: TargetContext<TContext, TInput>);
45
+ teardown(fn: TeardownFn<TContext>): Target<TContext, TInput>;
46
+ measure(title: string, run: StepFn<TContext, TInput>): Measure<TContext, TInput>;
47
+ }
48
+ export declare class FeedContext<TInput> {
49
+ readonly title: string;
50
+ readonly fn?: FeedFn<TInput> | undefined;
51
+ constructor(title: string, fn?: FeedFn<TInput> | undefined);
52
+ }
53
+ export declare class Benchmark<TInput> {
54
+ #private;
55
+ static create(title: string): Benchmark<void>;
56
+ static create<I>(title: string, fn: FeedFn<I>): Benchmark<I>;
57
+ constructor(title: string);
58
+ constructor(title: string, fn: FeedFn<TInput>);
59
+ feed(title: string): Benchmark<TInput | void>;
60
+ feed<I>(title: string, fn: FeedFn<I>): Benchmark<TInput | I>;
61
+ target<TContext>(title: string): Target<void, TInput>;
62
+ target<TContext>(title: string, setup: SetupFn<Awaited<TContext>>): Target<TContext, TInput>;
63
+ execute<R extends readonly ReportType[] = typeof DEFAULT_REPORT_TYPES>({ workers, warmupCycles, maxCycles, minCycles, absThreshold, relThreshold, reportTypes, }: ExecutorOptions<R>): Promise<TargetReport<R>[]>;
64
+ }
65
+ export declare const printSimpleReports: <R extends ReportTypeList>(reports: TargetReport<R>[]) => void;
66
+ export declare const printTableReports: <R extends ReportTypeList>(reports: TargetReport<R>[]) => void;
67
+ export declare const printJSONReports: <R extends ReportTypeList>(reports: TargetReport<R>[], padding?: number) => void;