@nestia/benchmark 10.0.2 → 11.0.0-dev.20260312

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.
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
3
  if (k2 === undefined) k2 = k;
15
4
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -52,78 +41,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
52
41
  step((generator = generator.apply(thisArg, _arguments || [])).next());
53
42
  });
54
43
  };
55
- var __generator = (this && this.__generator) || function (thisArg, body) {
56
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
57
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
58
- function verb(n) { return function (v) { return step([n, v]); }; }
59
- function step(op) {
60
- if (f) throw new TypeError("Generator is already executing.");
61
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
62
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
63
- if (y = 0, t) op = [op[0] & 2, t.value];
64
- switch (op[0]) {
65
- case 0: case 1: t = op; break;
66
- case 4: _.label++; return { value: op[1], done: false };
67
- case 5: _.label++; y = op[1]; op = [0]; continue;
68
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
69
- default:
70
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
71
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
72
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
73
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
74
- if (t[2]) _.ops.pop();
75
- _.trys.pop(); continue;
76
- }
77
- op = body.call(thisArg, _);
78
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
79
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
80
- }
81
- };
82
- var __values = (this && this.__values) || function(o) {
83
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
84
- if (m) return m.call(o);
85
- if (o && typeof o.length === "number") return {
86
- next: function () {
87
- if (o && i >= o.length) o = void 0;
88
- return { value: o && o[i++], done: !o };
89
- }
90
- };
91
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
92
- };
93
- var __read = (this && this.__read) || function (o, n) {
94
- var m = typeof Symbol === "function" && o[Symbol.iterator];
95
- if (!m) return o;
96
- var i = m.call(o), r, ar = [], e;
97
- try {
98
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
99
- }
100
- catch (error) { e = { error: error }; }
101
- finally {
102
- try {
103
- if (r && !r.done && (m = i["return"])) m.call(i);
104
- }
105
- finally { if (e) throw e.error; }
106
- }
107
- return ar;
108
- };
109
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
110
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
111
- if (ar || !(i in from)) {
112
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
113
- ar[i] = from[i];
114
- }
115
- }
116
- return to.concat(ar || Array.prototype.slice.call(from));
117
- };
118
44
  var __importDefault = (this && this.__importDefault) || function (mod) {
119
45
  return (mod && mod.__esModule) ? mod : { "default": mod };
120
46
  };
121
47
  Object.defineProperty(exports, "__esModule", { value: true });
122
48
  exports.DynamicBenchmarker = void 0;
123
- var fs_1 = __importDefault(require("fs"));
124
- var tgrid_1 = require("tgrid");
125
- var tstl_1 = require("tstl");
126
- var DynamicBenchmarkReporter_1 = require("./internal/DynamicBenchmarkReporter");
49
+ const fs_1 = __importDefault(require("fs"));
50
+ const tgrid_1 = require("tgrid");
51
+ const tstl_1 = require("tstl");
52
+ const DynamicBenchmarkReporter_1 = require("./internal/DynamicBenchmarkReporter");
127
53
  /**
128
54
  * Dynamic benchmark executor running prefixed functions.
129
55
  *
@@ -158,7 +84,6 @@ var DynamicBenchmarkReporter_1 = require("./internal/DynamicBenchmarkReporter");
158
84
  */
159
85
  var DynamicBenchmarker;
160
86
  (function (DynamicBenchmarker) {
161
- var _this = this;
162
87
  /**
163
88
  * Master program.
164
89
  *
@@ -170,116 +95,63 @@ var DynamicBenchmarker;
170
95
  * @param props Properties of the master program
171
96
  * @returns Benchmark report
172
97
  */
173
- DynamicBenchmarker.master = function (props) { return __awaiter(_this, void 0, void 0, function () {
174
- var completes, servants, started_at, memories, completed_at, events, endpoints, events_1, events_1_1, e;
175
- var e_1, _a;
176
- var _this = this;
177
- var _b;
178
- return __generator(this, function (_c) {
179
- switch (_c.label) {
180
- case 0:
181
- completes = new Array(props.threads).fill(0);
182
- return [4 /*yield*/, Promise.all(new Array(props.threads).fill(null).map(function (_, i) { return __awaiter(_this, void 0, void 0, function () {
183
- var connector;
184
- var _a;
185
- return __generator(this, function (_b) {
186
- switch (_b.label) {
187
- case 0:
188
- connector = new tgrid_1.WorkerConnector(null, {
189
- filter: (_a = props.filter) !== null && _a !== void 0 ? _a : (function () { return true; }),
190
- progress: function (current) {
191
- completes[i] = current;
192
- if (props.progress)
193
- props.progress(completes.reduce(function (a, b) { return a + b; }, 0));
194
- },
195
- }, "process");
196
- return [4 /*yield*/, connector.connect(props.servant, { stdio: props.stdio })];
197
- case 1:
198
- _b.sent();
199
- return [2 /*return*/, connector];
200
- }
201
- });
202
- }); }))];
203
- case 1:
204
- servants = _c.sent();
205
- started_at = new Date();
206
- memories = [];
207
- completed_at = null;
208
- (function () { return __awaiter(_this, void 0, void 0, function () {
209
- var getter, _a, _b;
210
- var _c;
211
- var _this = this;
212
- var _d;
213
- return __generator(this, function (_e) {
214
- switch (_e.label) {
215
- case 0:
216
- getter = (_d = props.memory) !== null && _d !== void 0 ? _d : (function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
217
- return [2 /*return*/, process.memoryUsage()];
218
- }); }); });
219
- _e.label = 1;
220
- case 1:
221
- if (!(completed_at === null)) return [3 /*break*/, 4];
222
- return [4 /*yield*/, (0, tstl_1.sleep_for)(1000)];
223
- case 2:
224
- _e.sent();
225
- _b = (_a = memories).push;
226
- _c = {};
227
- return [4 /*yield*/, getter()];
228
- case 3:
229
- _b.apply(_a, [(_c.usage = _e.sent(),
230
- _c.time = new Date().toISOString(),
231
- _c)]);
232
- return [3 /*break*/, 1];
233
- case 4: return [2 /*return*/];
234
- }
235
- });
236
- }); })().catch(function () { });
237
- return [4 /*yield*/, Promise.all(servants.map(function (connector) {
238
- return connector.getDriver().execute({
239
- count: Math.ceil(props.count / props.threads),
240
- simultaneous: Math.ceil(props.simultaneous / props.threads),
241
- });
242
- }))];
243
- case 2:
244
- events = (_c.sent()).flat();
245
- completed_at = new Date();
246
- return [4 /*yield*/, Promise.all(servants.map(function (connector) { return connector.close(); }))];
247
- case 3:
248
- _c.sent();
98
+ DynamicBenchmarker.master = (props) => __awaiter(this, void 0, void 0, function* () {
99
+ var _a;
100
+ const completes = new Array(props.threads).fill(0);
101
+ const servants = yield Promise.all(new Array(props.threads).fill(null).map((_, i) => __awaiter(this, void 0, void 0, function* () {
102
+ var _a;
103
+ const connector = new tgrid_1.WorkerConnector(null, {
104
+ filter: (_a = props.filter) !== null && _a !== void 0 ? _a : (() => true),
105
+ progress: (current) => {
106
+ completes[i] = current;
249
107
  if (props.progress)
250
- props.progress(props.count);
251
- endpoints = new tstl_1.HashMap(function (key) { return (0, tstl_1.hash)(key.method, key.path); }, function (x, y) { return x.method === y.method && x.path === y.path; });
252
- try {
253
- for (events_1 = __values(events), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) {
254
- e = events_1_1.value;
255
- endpoints
256
- .take({
257
- method: e.metadata.method,
258
- path: (_b = e.metadata.template) !== null && _b !== void 0 ? _b : e.metadata.path,
259
- }, function () { return []; })
260
- .push(e);
261
- }
262
- }
263
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
264
- finally {
265
- try {
266
- if (events_1_1 && !events_1_1.done && (_a = events_1.return)) _a.call(events_1);
267
- }
268
- finally { if (e_1) throw e_1.error; }
269
- }
270
- return [2 /*return*/, {
271
- count: props.count,
272
- threads: props.threads,
273
- simultaneous: props.simultaneous,
274
- statistics: statistics(events),
275
- endpoints: __spreadArray([], __read(endpoints), false).map(function (it) { return (__assign(__assign({}, statistics(it.second)), it.first)); }),
276
- started_at: started_at.toISOString(),
277
- completed_at: completed_at.toISOString(),
278
- memories: memories,
279
- }];
108
+ props.progress(completes.reduce((a, b) => a + b, 0));
109
+ },
110
+ }, "process");
111
+ yield connector.connect(props.servant, { stdio: props.stdio });
112
+ return connector;
113
+ })));
114
+ const started_at = new Date();
115
+ const memories = [];
116
+ let completed_at = null;
117
+ (() => __awaiter(this, void 0, void 0, function* () {
118
+ var _a;
119
+ const getter = (_a = props.memory) !== null && _a !== void 0 ? _a : (() => __awaiter(this, void 0, void 0, function* () { return process.memoryUsage(); }));
120
+ while (completed_at === null) {
121
+ yield (0, tstl_1.sleep_for)(1000);
122
+ memories.push({
123
+ usage: yield getter(),
124
+ time: new Date().toISOString(),
125
+ });
280
126
  }
281
- });
282
- }); };
127
+ }))().catch(() => { });
128
+ const events = (yield Promise.all(servants.map((connector) => connector.getDriver().execute({
129
+ count: Math.ceil(props.count / props.threads),
130
+ simultaneous: Math.ceil(props.simultaneous / props.threads),
131
+ })))).flat();
132
+ completed_at = new Date();
133
+ yield Promise.all(servants.map((connector) => connector.close()));
134
+ if (props.progress)
135
+ props.progress(props.count);
136
+ const endpoints = new tstl_1.HashMap((key) => (0, tstl_1.hash)(key.method, key.path), (x, y) => x.method === y.method && x.path === y.path);
137
+ for (const e of events)
138
+ endpoints
139
+ .take({
140
+ method: e.metadata.method,
141
+ path: (_a = e.metadata.template) !== null && _a !== void 0 ? _a : e.metadata.path,
142
+ }, () => [])
143
+ .push(e);
144
+ return {
145
+ count: props.count,
146
+ threads: props.threads,
147
+ simultaneous: props.simultaneous,
148
+ statistics: statistics(events),
149
+ endpoints: [...endpoints].map((it) => (Object.assign(Object.assign({}, statistics(it.second)), it.first))),
150
+ started_at: started_at.toISOString(),
151
+ completed_at: completed_at.toISOString(),
152
+ memories,
153
+ };
154
+ });
283
155
  /**
284
156
  * Create a servant program.
285
157
  *
@@ -288,229 +160,95 @@ var DynamicBenchmarker;
288
160
  * @param props Properties of the servant program
289
161
  * @returns Servant program as a worker server
290
162
  */
291
- DynamicBenchmarker.servant = function (props) { return __awaiter(_this, void 0, void 0, function () {
292
- var server;
293
- return __generator(this, function (_a) {
294
- switch (_a.label) {
295
- case 0:
296
- server = new tgrid_1.WorkerServer();
297
- return [4 /*yield*/, server.open({
298
- execute: execute({
299
- driver: server.getDriver(),
300
- props: props,
301
- }),
302
- })];
303
- case 1:
304
- _a.sent();
305
- return [2 /*return*/, server];
306
- }
163
+ DynamicBenchmarker.servant = (props) => __awaiter(this, void 0, void 0, function* () {
164
+ const server = new tgrid_1.WorkerServer();
165
+ yield server.open({
166
+ execute: execute({
167
+ driver: server.getDriver(),
168
+ props,
169
+ }),
307
170
  });
308
- }); };
171
+ return server;
172
+ });
309
173
  /**
310
174
  * Convert the benchmark report to markdown content.
311
175
  *
312
176
  * @param report Benchmark report
313
177
  * @returns Markdown content
314
178
  */
315
- DynamicBenchmarker.markdown = function (report) {
316
- return DynamicBenchmarkReporter_1.DynamicBenchmarkReporter.markdown(report);
317
- };
318
- var execute = function (ctx) {
319
- return function (mass) { return __awaiter(_this, void 0, void 0, function () {
320
- var functions, entireEvents;
321
- var _this = this;
322
- return __generator(this, function (_a) {
323
- switch (_a.label) {
324
- case 0:
325
- functions = [];
326
- return [4 /*yield*/, iterate({
327
- collection: functions,
328
- driver: ctx.driver,
329
- props: ctx.props,
330
- })(ctx.props.location)];
331
- case 1:
332
- _a.sent();
333
- entireEvents = [];
334
- return [4 /*yield*/, Promise.all(new Array(mass.simultaneous)
335
- .fill(null)
336
- .map(function () { return 1; })
337
- .map(function () { return __awaiter(_this, void 0, void 0, function () {
338
- var _loop_1;
339
- var _this = this;
340
- return __generator(this, function (_a) {
341
- switch (_a.label) {
342
- case 0:
343
- _loop_1 = function () {
344
- var localEvents, func, connection, exp_1, localEvents_1, localEvents_1_1, e;
345
- var e_2, _b;
346
- return __generator(this, function (_c) {
347
- switch (_c.label) {
348
- case 0:
349
- localEvents = [];
350
- func = functions[Math.floor(Math.random() * functions.length)];
351
- connection = __assign(__assign({}, ctx.props.connection), { logger: function (fe) { return __awaiter(_this, void 0, void 0, function () {
352
- var be;
353
- var _a, _b;
354
- return __generator(this, function (_c) {
355
- be = {
356
- metadata: fe.route,
357
- status: fe.status,
358
- started_at: fe.started_at.toISOString(),
359
- respond_at: (_b = (_a = fe.respond_at) === null || _a === void 0 ? void 0 : _a.toISOString()) !== null && _b !== void 0 ? _b : null,
360
- completed_at: fe.completed_at.toISOString(),
361
- success: true,
362
- };
363
- localEvents.push(be);
364
- entireEvents.push(be);
365
- return [2 /*return*/];
366
- });
367
- }); } });
368
- _c.label = 1;
369
- case 1:
370
- _c.trys.push([1, 3, , 4]);
371
- return [4 /*yield*/, func.value.apply(func, __spreadArray([], __read(ctx.props.parameters(connection, func.key)), false))];
372
- case 2:
373
- _c.sent();
374
- return [3 /*break*/, 4];
375
- case 3:
376
- exp_1 = _c.sent();
377
- try {
378
- for (localEvents_1 = (e_2 = void 0, __values(localEvents)), localEvents_1_1 = localEvents_1.next(); !localEvents_1_1.done; localEvents_1_1 = localEvents_1.next()) {
379
- e = localEvents_1_1.value;
380
- e.success = e.status === 200 || e.status === 201;
381
- }
382
- }
383
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
384
- finally {
385
- try {
386
- if (localEvents_1_1 && !localEvents_1_1.done && (_b = localEvents_1.return)) _b.call(localEvents_1);
387
- }
388
- finally { if (e_2) throw e_2.error; }
389
- }
390
- return [3 /*break*/, 4];
391
- case 4:
392
- if (localEvents.length !== 0)
393
- ctx.driver.progress(entireEvents.length).catch(function () { });
394
- return [2 /*return*/];
395
- }
396
- });
397
- };
398
- _a.label = 1;
399
- case 1:
400
- if (!(entireEvents.length < mass.count)) return [3 /*break*/, 3];
401
- return [5 /*yield**/, _loop_1()];
402
- case 2:
403
- _a.sent();
404
- return [3 /*break*/, 1];
405
- case 3: return [2 /*return*/];
406
- }
407
- });
408
- }); }))];
409
- case 2:
410
- _a.sent();
411
- return [4 /*yield*/, ctx.driver.progress(entireEvents.length)];
412
- case 3:
413
- _a.sent();
414
- return [2 /*return*/, entireEvents];
179
+ DynamicBenchmarker.markdown = (report) => DynamicBenchmarkReporter_1.DynamicBenchmarkReporter.markdown(report);
180
+ const execute = (ctx) => (mass) => __awaiter(this, void 0, void 0, function* () {
181
+ const functions = [];
182
+ yield iterate({
183
+ collection: functions,
184
+ driver: ctx.driver,
185
+ props: ctx.props,
186
+ })(ctx.props.location);
187
+ const entireEvents = [];
188
+ yield Promise.all(new Array(mass.simultaneous)
189
+ .fill(null)
190
+ .map(() => 1)
191
+ .map(() => __awaiter(this, void 0, void 0, function* () {
192
+ while (entireEvents.length < mass.count) {
193
+ const localEvents = [];
194
+ const func = functions[Math.floor(Math.random() * functions.length)];
195
+ const connection = Object.assign(Object.assign({}, ctx.props.connection), { logger: (fe) => __awaiter(this, void 0, void 0, function* () {
196
+ var _a, _b;
197
+ const be = {
198
+ metadata: fe.route,
199
+ status: fe.status,
200
+ started_at: fe.started_at.toISOString(),
201
+ respond_at: (_b = (_a = fe.respond_at) === null || _a === void 0 ? void 0 : _a.toISOString()) !== null && _b !== void 0 ? _b : null,
202
+ completed_at: fe.completed_at.toISOString(),
203
+ success: true,
204
+ };
205
+ localEvents.push(be);
206
+ entireEvents.push(be);
207
+ }) });
208
+ try {
209
+ yield func.value(...ctx.props.parameters(connection, func.key));
415
210
  }
416
- });
417
- }); };
418
- };
211
+ catch (exp) {
212
+ for (const e of localEvents)
213
+ e.success = e.status === 200 || e.status === 201;
214
+ }
215
+ if (localEvents.length !== 0)
216
+ ctx.driver.progress(entireEvents.length).catch(() => { });
217
+ }
218
+ })));
219
+ yield ctx.driver.progress(entireEvents.length);
220
+ return entireEvents;
221
+ });
419
222
  })(DynamicBenchmarker || (exports.DynamicBenchmarker = DynamicBenchmarker = {}));
420
- var iterate = function (ctx) {
421
- return function (path) { return __awaiter(void 0, void 0, void 0, function () {
422
- var directory, directory_1, directory_1_1, file, location_1, stat, modulo, _a, _b, _c, key, value, e_3_1, e_4_1;
423
- var e_4, _d, e_3, _e;
424
- return __generator(this, function (_f) {
425
- switch (_f.label) {
426
- case 0: return [4 /*yield*/, fs_1.default.promises.readdir(path)];
427
- case 1:
428
- directory = _f.sent();
429
- _f.label = 2;
430
- case 2:
431
- _f.trys.push([2, 20, 21, 22]);
432
- directory_1 = __values(directory), directory_1_1 = directory_1.next();
433
- _f.label = 3;
434
- case 3:
435
- if (!!directory_1_1.done) return [3 /*break*/, 19];
436
- file = directory_1_1.value;
437
- location_1 = "".concat(path, "/").concat(file);
438
- return [4 /*yield*/, fs_1.default.promises.stat(location_1)];
439
- case 4:
440
- stat = _f.sent();
441
- if (!(stat.isDirectory() === true)) return [3 /*break*/, 6];
442
- return [4 /*yield*/, iterate(ctx)(location_1)];
443
- case 5:
444
- _f.sent();
445
- return [3 /*break*/, 18];
446
- case 6:
447
- if (!(file.endsWith(".js") === true)) return [3 /*break*/, 18];
448
- return [4 /*yield*/, Promise.resolve("".concat(location_1)).then(function (s) { return __importStar(require(s)); })];
449
- case 7:
450
- modulo = _f.sent();
451
- _f.label = 8;
452
- case 8:
453
- _f.trys.push([8, 16, 17, 18]);
454
- _a = (e_3 = void 0, __values(Object.entries(modulo))), _b = _a.next();
455
- _f.label = 9;
456
- case 9:
457
- if (!!_b.done) return [3 /*break*/, 15];
458
- _c = __read(_b.value, 2), key = _c[0], value = _c[1];
459
- if (!(typeof value !== "function")) return [3 /*break*/, 10];
460
- return [3 /*break*/, 14];
461
- case 10:
462
- if (!(key.startsWith(ctx.props.prefix) === false)) return [3 /*break*/, 11];
463
- return [3 /*break*/, 14];
464
- case 11: return [4 /*yield*/, ctx.driver.filter(key)];
465
- case 12:
466
- if ((_f.sent()) === false)
467
- return [3 /*break*/, 14];
468
- _f.label = 13;
469
- case 13:
470
- ctx.collection.push({
471
- key: key,
472
- value: value,
473
- });
474
- _f.label = 14;
475
- case 14:
476
- _b = _a.next();
477
- return [3 /*break*/, 9];
478
- case 15: return [3 /*break*/, 18];
479
- case 16:
480
- e_3_1 = _f.sent();
481
- e_3 = { error: e_3_1 };
482
- return [3 /*break*/, 18];
483
- case 17:
484
- try {
485
- if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
486
- }
487
- finally { if (e_3) throw e_3.error; }
488
- return [7 /*endfinally*/];
489
- case 18:
490
- directory_1_1 = directory_1.next();
491
- return [3 /*break*/, 3];
492
- case 19: return [3 /*break*/, 22];
493
- case 20:
494
- e_4_1 = _f.sent();
495
- e_4 = { error: e_4_1 };
496
- return [3 /*break*/, 22];
497
- case 21:
498
- try {
499
- if (directory_1_1 && !directory_1_1.done && (_d = directory_1.return)) _d.call(directory_1);
500
- }
501
- finally { if (e_4) throw e_4.error; }
502
- return [7 /*endfinally*/];
503
- case 22: return [2 /*return*/];
223
+ const iterate = (ctx) => (path) => __awaiter(void 0, void 0, void 0, function* () {
224
+ const directory = yield fs_1.default.promises.readdir(path);
225
+ for (const file of directory) {
226
+ const location = `${path}/${file}`;
227
+ const stat = yield fs_1.default.promises.stat(location);
228
+ if (stat.isDirectory() === true)
229
+ yield iterate(ctx)(location);
230
+ else if (file.endsWith(__filename.substr(-3)) === true) {
231
+ const modulo = yield Promise.resolve(`${location}`).then(s => __importStar(require(s)));
232
+ for (const [key, value] of Object.entries(modulo)) {
233
+ if (typeof value !== "function")
234
+ continue;
235
+ else if (key.startsWith(ctx.props.prefix) === false)
236
+ continue;
237
+ else if ((yield ctx.driver.filter(key)) === false)
238
+ continue;
239
+ ctx.collection.push({
240
+ key,
241
+ value: value,
242
+ });
504
243
  }
505
- });
506
- }); };
507
- };
508
- var statistics = function (events) {
509
- var successes = events.filter(function (event) { return event.success; });
510
- return __assign({ count: events.length, success: successes.length }, average(events));
244
+ }
245
+ }
246
+ });
247
+ const statistics = (events) => {
248
+ const successes = events.filter((event) => event.success);
249
+ return Object.assign({ count: events.length, success: successes.length }, average(events));
511
250
  };
512
- var average = function (events) {
513
- var e_5, _a;
251
+ const average = (events) => {
514
252
  if (events.length === 0)
515
253
  return {
516
254
  mean: null,
@@ -518,30 +256,20 @@ var average = function (events) {
518
256
  minimum: null,
519
257
  maximum: null,
520
258
  };
521
- var mean = 0;
522
- var stdev = 0;
523
- var minimum = Number.MAX_SAFE_INTEGER;
524
- var maximum = Number.MIN_SAFE_INTEGER;
525
- try {
526
- for (var events_2 = __values(events), events_2_1 = events_2.next(); !events_2_1.done; events_2_1 = events_2.next()) {
527
- var event_1 = events_2_1.value;
528
- var elapsed = new Date(event_1.completed_at).getTime() -
529
- new Date(event_1.started_at).getTime();
530
- mean += elapsed;
531
- stdev += elapsed * elapsed;
532
- minimum = Math.min(minimum, elapsed);
533
- maximum = Math.max(maximum, elapsed);
534
- }
535
- }
536
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
537
- finally {
538
- try {
539
- if (events_2_1 && !events_2_1.done && (_a = events_2.return)) _a.call(events_2);
540
- }
541
- finally { if (e_5) throw e_5.error; }
259
+ let mean = 0;
260
+ let stdev = 0;
261
+ let minimum = Number.MAX_SAFE_INTEGER;
262
+ let maximum = Number.MIN_SAFE_INTEGER;
263
+ for (const event of events) {
264
+ const elapsed = new Date(event.completed_at).getTime() -
265
+ new Date(event.started_at).getTime();
266
+ mean += elapsed;
267
+ stdev += elapsed * elapsed;
268
+ minimum = Math.min(minimum, elapsed);
269
+ maximum = Math.max(maximum, elapsed);
542
270
  }
543
271
  mean /= events.length;
544
272
  stdev = Math.sqrt(stdev / events.length - mean * mean);
545
- return { mean: mean, stdev: stdev, minimum: minimum, maximum: maximum };
273
+ return { mean, stdev, minimum, maximum };
546
274
  };
547
275
  //# sourceMappingURL=DynamicBenchmarker.js.map