@naturalcycles/bench-lib 1.6.3 → 1.6.5

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.
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runBench = exports.runBenchScript = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
6
- const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
5
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
+ const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
7
+ const nodejs_lib_3 = require("@naturalcycles/nodejs-lib");
7
8
  const Benchmark = require("benchmark");
8
- const fs = require("fs-extra");
9
9
  const vega = require("vega");
10
10
  const vegaLite = require("vega-lite");
11
11
  const asciiChart_util_1 = require("./asciiChart.util");
@@ -15,7 +15,7 @@ const asciiChart_util_1 = require("./asciiChart.util");
15
15
  function runBenchScript(opt) {
16
16
  // fake timeout is needed to workaround `benchmark` process exiting too early when 2+ runs are used
17
17
  const timeout = setTimeout(() => { }, 10000000);
18
- (0, script_1.runScript)(async () => {
18
+ (0, nodejs_lib_3.runScript)(async () => {
19
19
  await runBench(opt);
20
20
  clearTimeout(timeout);
21
21
  });
@@ -46,19 +46,19 @@ async function runBench(opt) {
46
46
  // names.forEach(name => {
47
47
  // summary[name] = results.hz.map(map => map[name]!)
48
48
  // })
49
- fs.ensureDirSync(reportDirPath);
49
+ (0, nodejs_lib_1._ensureDirSync)(reportDirPath);
50
50
  const summaryJsonPath = `${reportDirPath}/${name}.json`;
51
- fs.writeJsonSync(summaryJsonPath, avg, { spaces: 2 });
52
- console.log(`saved ${(0, colors_1.dimGrey)(summaryJsonPath)}`);
51
+ (0, nodejs_lib_1._writeJsonSync)(summaryJsonPath, avg, { spaces: 2 });
52
+ console.log(`saved ${(0, nodejs_lib_2.dimGrey)(summaryJsonPath)}`);
53
53
  }
54
54
  if (writePlot) {
55
- fs.ensureDirSync(reportDirPath);
55
+ (0, nodejs_lib_1._ensureDirSync)(reportDirPath);
56
56
  const spec = benchResultsToVegaSpec(avg);
57
57
  const view = new vega.View(vega.parse(spec), { renderer: 'none' });
58
58
  const svg = await view.toSVG();
59
59
  const plotPath = `${reportDirPath}/${name}.svg`;
60
- fs.writeFileSync(plotPath, svg);
61
- console.log(`saved ${(0, colors_1.dimGrey)(plotPath)}`);
60
+ (0, nodejs_lib_1._writeFileSync)(plotPath, svg);
61
+ console.log(`saved ${(0, nodejs_lib_2.dimGrey)(plotPath)}`);
62
62
  }
63
63
  if (asciiPlot) {
64
64
  console.log('\n' + (0, asciiChart_util_1.plotAsciiChart)(avg));
@@ -74,7 +74,7 @@ async function runBenchOnce(opt, run) {
74
74
  // console.log(event.target)
75
75
  })
76
76
  .on('complete', function () {
77
- console.log(`Fastest in run ${(0, colors_1.yellow)(run)} is ` + this.filter('fastest').map('name'));
77
+ console.log(`Fastest in run ${(0, nodejs_lib_2.yellow)(run)} is ` + this.filter('fastest').map('name'));
78
78
  // console.log(this[0].stats)
79
79
  // console.log(this)
80
80
  const results = {};
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCannon = exports.runCannonScript = void 0;
4
- const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
4
+ const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
+ const nodejs_lib_2 = require("@naturalcycles/nodejs-lib");
5
6
  const js_lib_1 = require("@naturalcycles/js-lib");
6
- const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
7
- const fs = require("fs-extra");
7
+ const nodejs_lib_3 = require("@naturalcycles/nodejs-lib");
8
8
  const vega = require("vega");
9
9
  const vegaLite = require("vega-lite");
10
10
  /**
@@ -13,7 +13,7 @@ const vegaLite = require("vega-lite");
13
13
  function runCannonScript(profiles, optInput = {}) {
14
14
  // fake timeout is needed to workaround `benchmark` process exiting too early when 2+ runs are used
15
15
  const timeout = setTimeout(() => { }, 10000000);
16
- (0, script_1.runScript)(async () => {
16
+ (0, nodejs_lib_2.runScript)(async () => {
17
17
  await runCannon(profiles, optInput);
18
18
  clearTimeout(timeout);
19
19
  });
@@ -53,7 +53,7 @@ async function runCannon(profiles, optInput = {}) {
53
53
  });
54
54
  }
55
55
  const { reportDirPath } = opt;
56
- fs.ensureDirSync(reportDirPath);
56
+ (0, nodejs_lib_1._ensureDirSync)(reportDirPath);
57
57
  const resultByProfile = {};
58
58
  const summaries = [];
59
59
  for await (const profileName of Object.keys(profiles)) {
@@ -67,11 +67,11 @@ async function runCannon(profiles, optInput = {}) {
67
67
  console.table(summaries);
68
68
  if (opt.writeSummary) {
69
69
  const summaryJsonPath = `${reportDirPath}/${opt.name}.summary.json`;
70
- fs.writeJsonSync(summaryJsonPath, summaries, { spaces: 2 });
71
- console.log(`saved ${(0, colors_1.dimGrey)(summaryJsonPath)}`);
70
+ (0, nodejs_lib_1._writeJsonSync)(summaryJsonPath, summaries, { spaces: 2 });
71
+ console.log(`saved ${(0, nodejs_lib_3.dimGrey)(summaryJsonPath)}`);
72
72
  }
73
73
  if (opt.writeRawSummary) {
74
- fs.writeJsonSync(`${reportDirPath}/${opt.name}.rawSummary.json`, resultByProfile, { spaces: 2 });
74
+ (0, nodejs_lib_1._writeJsonSync)(`${reportDirPath}/${opt.name}.rawSummary.json`, resultByProfile, { spaces: 2 });
75
75
  }
76
76
  if (opt.writePlots) {
77
77
  await writePlotFiles(opt, summaries);
@@ -88,7 +88,7 @@ async function runCannonProfile(profileName, serverFactory, opt) {
88
88
  const url = `${host}:${port}${opt.path}`;
89
89
  let finalResult = undefined;
90
90
  for await (const run of (0, js_lib_1._range)(1, runs + 1)) {
91
- console.log(`\n${(0, colors_1.boldRed)('=== ' + profileName + ' ===')} run ${(0, colors_1.yellow)(run)}/${(0, colors_1.yellow)(runs)}\n`);
91
+ console.log(`\n${(0, nodejs_lib_3.boldRed)('=== ' + profileName + ' ===')} run ${(0, nodejs_lib_3.yellow)(run)}/${(0, nodejs_lib_3.yellow)(runs)}\n`);
92
92
  const doneDefer = (0, js_lib_1.pDefer)();
93
93
  const instance = autocannon({
94
94
  url,
@@ -112,7 +112,7 @@ async function runCannonProfile(profileName, serverFactory, opt) {
112
112
  });
113
113
  finalResult = await doneDefer;
114
114
  if (!silent)
115
- console.log((0, colors_1.dimGrey)(`cooldown ${(0, colors_1.yellow)(cooldown)} seconds...`));
115
+ console.log((0, nodejs_lib_3.dimGrey)(`cooldown ${(0, nodejs_lib_3.yellow)(cooldown)} seconds...`));
116
116
  await (0, js_lib_1.pDelay)(cooldown * 1000);
117
117
  }
118
118
  await new Promise(resolve => server.close(resolve));
@@ -135,7 +135,7 @@ function toSummary(name, result) {
135
135
  }
136
136
  async function writePlotFiles(opt, summaries) {
137
137
  const { reportDirPath, name } = opt;
138
- fs.ensureDirSync(reportDirPath);
138
+ (0, nodejs_lib_1._ensureDirSync)(reportDirPath);
139
139
  let fields = ['rpsAvg', 'latencyAvg', 'latency50', 'latency90', 'latency99', 'throughputAvg'];
140
140
  if (!opt.includeLatencyPercentiles) {
141
141
  fields = fields.filter(f => !f.startsWith('latency') || f === 'latencyAvg');
@@ -147,9 +147,9 @@ async function writePlotFiles(opt, summaries) {
147
147
  // generate a static SVG image
148
148
  const svg = await view.toSVG();
149
149
  // console.log(svg)
150
- fs.writeFileSync(`${reportDirPath}/${name}.${specName}.svg`, svg);
150
+ (0, nodejs_lib_1._writeFileSync)(`${reportDirPath}/${name}.${specName}.svg`, svg);
151
151
  });
152
- fs.writeFileSync(`${reportDirPath}/${name}.md`, mdContent(opt, Object.keys(specs)));
152
+ (0, nodejs_lib_1._writeFileSync)(`${reportDirPath}/${name}.md`, mdContent(opt, Object.keys(specs)));
153
153
  }
154
154
  function autocannonSummaryToVegaSpecs(fields, summaries) {
155
155
  // console.log(summary)
package/package.json CHANGED
@@ -9,7 +9,6 @@
9
9
  "autocannon": "^7.0.0",
10
10
  "benchmark": "^2.1.4",
11
11
  "express": "^4.17.1",
12
- "fs-extra": "^11.1.0",
13
12
  "helmet": "^7.0.0",
14
13
  "vega": "^5.10.1",
15
14
  "vega-lite": "^5.0.0"
@@ -37,7 +36,7 @@
37
36
  "engines": {
38
37
  "node": ">=16.10.0"
39
38
  },
40
- "version": "1.6.3",
39
+ "version": "1.6.5",
41
40
  "description": "Benchmarking library, based on Benchmark.js and Autocannon",
42
41
  "author": "Natural Cycles Team",
43
42
  "license": "MIT"