@naturalcycles/bench-lib 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,15 +1,10 @@
1
- export interface BenchDeferred {
2
- resolve: () => void;
3
- }
4
- export type BenchDeferredFunction = (done: BenchDeferred) => any;
1
+ export type BenchFunction = () => void;
5
2
  export interface RunBenchOptions {
6
3
  /**
7
4
  * Functions to benchmark.
8
- * Record from function name to a `BenchDeferredFunction`.
9
- * BenchDeferredFunction takes `done` callback as a first argument,
10
- * `done.resolve()` HAS to be called at the end of your function.
5
+ * Record from function name to a `BenchFunction`.
11
6
  */
12
- fns: Record<string, BenchDeferredFunction>;
7
+ fns: Record<string, BenchFunction>;
13
8
  /**
14
9
  * How many times to run.
15
10
  * Every second run will be in reverse order.
@@ -1,4 +1,3 @@
1
- import { BenchDeferredFunction } from './bench.model';
2
- export declare const benchNoopFn: BenchDeferredFunction;
3
- export declare const benchRandomFn: BenchDeferredFunction;
4
- export declare const benchPDelayFn: BenchDeferredFunction;
1
+ import { BenchFunction } from './bench.model';
2
+ export declare const benchNoopFn: BenchFunction;
3
+ export declare const benchRandomFn: BenchFunction;
@@ -1,16 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.benchPDelayFn = exports.benchRandomFn = exports.benchNoopFn = void 0;
3
+ exports.benchRandomFn = exports.benchNoopFn = void 0;
4
4
  const js_lib_1 = require("@naturalcycles/js-lib");
5
- const benchNoopFn = done => done.resolve();
5
+ const benchNoopFn = () => { };
6
6
  exports.benchNoopFn = benchNoopFn;
7
- const benchRandomFn = done => {
7
+ const benchRandomFn = () => {
8
8
  const _ = (0, js_lib_1._randomInt)(1, 10);
9
- done.resolve();
10
9
  };
11
10
  exports.benchRandomFn = benchRandomFn;
12
- const benchPDelayFn = async (done) => {
13
- await (0, js_lib_1.pDelay)();
14
- done.resolve();
15
- };
16
- exports.benchPDelayFn = benchPDelayFn;
@@ -91,7 +91,7 @@ async function runBenchOnce(opt, run) {
91
91
  fnNames.reverse();
92
92
  fnNames.forEach(name => {
93
93
  suite.add(opt.fns[name], {
94
- defer: true,
94
+ defer: false, // used to be true
95
95
  name,
96
96
  });
97
97
  });
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.expressSyncFunctionFactory = exports.expressFunctionFactory = exports.expressWithMiddlewaresServerFactory = exports.bareExpressServerFactory = exports.bareNodeServerFactory = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const node_http_1 = tslib_1.__importDefault(require("node:http"));
6
- const express_1 = tslib_1.__importDefault(require("express"));
7
- const helmet_1 = tslib_1.__importDefault(require("helmet"));
8
6
  const bareNodeServerFactory = async () => {
9
7
  return node_http_1.default.createServer((req, res) => {
10
8
  res.setHeader('content-type', 'application/json; charset=utf-8');
@@ -13,7 +11,7 @@ const bareNodeServerFactory = async () => {
13
11
  };
14
12
  exports.bareNodeServerFactory = bareNodeServerFactory;
15
13
  const bareExpressServerFactory = async () => {
16
- const app = (0, express_1.default)();
14
+ const app = require('express')();
17
15
  app.disable('etag');
18
16
  app.disable('x-powered-by');
19
17
  app.get('/', (req, res) => res.json({ hello: 'world' }));
@@ -24,16 +22,17 @@ exports.bareExpressServerFactory = bareExpressServerFactory;
24
22
  * Based on: https://github.com/fastify/benchmarks/blob/master/benchmarks/express-with-middlewares.js
25
23
  */
26
24
  const expressWithMiddlewaresServerFactory = async () => {
27
- const app = (0, express_1.default)();
25
+ const app = require('express')();
26
+ const helmet = require('helmet');
28
27
  app.disable('etag');
29
28
  app.disable('x-powered-by');
30
29
  app.use(require('cors')());
31
- app.use(helmet_1.default.dnsPrefetchControl());
32
- app.use(helmet_1.default.frameguard());
33
- app.use(helmet_1.default.hidePoweredBy());
34
- app.use(helmet_1.default.hsts());
35
- app.use(helmet_1.default.ieNoOpen());
36
- app.use(helmet_1.default.xssFilter());
30
+ app.use(helmet.dnsPrefetchControl());
31
+ app.use(helmet.frameguard());
32
+ app.use(helmet.hidePoweredBy());
33
+ app.use(helmet.hsts());
34
+ app.use(helmet.ieNoOpen());
35
+ app.use(helmet.xssFilter());
37
36
  app.get('/', (req, res) => res.json({ hello: 'world' }));
38
37
  return node_http_1.default.createServer(app);
39
38
  };
@@ -43,7 +42,7 @@ exports.expressWithMiddlewaresServerFactory = expressWithMiddlewaresServerFactor
43
42
  */
44
43
  function expressFunctionFactory(fn) {
45
44
  return async () => {
46
- const app = (0, express_1.default)();
45
+ const app = require('express')();
47
46
  app.disable('etag');
48
47
  app.disable('x-powered-by');
49
48
  app.get('/', async (req, res) => res.json(await fn()));
@@ -53,7 +52,7 @@ function expressFunctionFactory(fn) {
53
52
  exports.expressFunctionFactory = expressFunctionFactory;
54
53
  function expressSyncFunctionFactory(fn) {
55
54
  return async () => {
56
- const app = (0, express_1.default)();
55
+ const app = require('express')();
57
56
  app.disable('etag');
58
57
  app.disable('x-powered-by');
59
58
  app.get('/', (req, res) => res.json(fn()));
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- import { BenchDeferredFunction, HertzMap, RunBenchOptions } from './bench.model';
2
- import { benchNoopFn } from './bench.profles';
3
- import { runBench, runBenchScript } from './bench.util';
4
- import { AutocannonOptions, AutocannonResult, AutocannonSummary, HttpServerFactory, RunCannonOptions } from './cannon.model';
5
- import { bareExpressServerFactory, bareNodeServerFactory, expressFunctionFactory, expressWithMiddlewaresServerFactory } from './cannon.profiles';
6
- import { runCannon, runCannonScript } from './cannon.util';
7
- export type { RunBenchOptions, BenchDeferredFunction, HertzMap, HttpServerFactory, RunCannonOptions, AutocannonSummary, AutocannonResult, AutocannonOptions, };
8
- export { runBenchScript, runBench, benchNoopFn, runCannon, runCannonScript, bareNodeServerFactory, bareExpressServerFactory, expressWithMiddlewaresServerFactory, expressFunctionFactory, };
1
+ export * from './bench.model';
2
+ export * from './bench.profles';
3
+ export * from './bench.util';
4
+ export * from './cannon.model';
5
+ export * from './cannon.profiles';
6
+ export * from './cannon.util';
package/dist/index.js CHANGED
@@ -1,16 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.expressFunctionFactory = exports.expressWithMiddlewaresServerFactory = exports.bareExpressServerFactory = exports.bareNodeServerFactory = exports.runCannonScript = exports.runCannon = exports.benchNoopFn = exports.runBench = exports.runBenchScript = void 0;
4
- const bench_profles_1 = require("./bench.profles");
5
- Object.defineProperty(exports, "benchNoopFn", { enumerable: true, get: function () { return bench_profles_1.benchNoopFn; } });
6
- const bench_util_1 = require("./bench.util");
7
- Object.defineProperty(exports, "runBench", { enumerable: true, get: function () { return bench_util_1.runBench; } });
8
- Object.defineProperty(exports, "runBenchScript", { enumerable: true, get: function () { return bench_util_1.runBenchScript; } });
9
- const cannon_profiles_1 = require("./cannon.profiles");
10
- Object.defineProperty(exports, "bareExpressServerFactory", { enumerable: true, get: function () { return cannon_profiles_1.bareExpressServerFactory; } });
11
- Object.defineProperty(exports, "bareNodeServerFactory", { enumerable: true, get: function () { return cannon_profiles_1.bareNodeServerFactory; } });
12
- Object.defineProperty(exports, "expressFunctionFactory", { enumerable: true, get: function () { return cannon_profiles_1.expressFunctionFactory; } });
13
- Object.defineProperty(exports, "expressWithMiddlewaresServerFactory", { enumerable: true, get: function () { return cannon_profiles_1.expressWithMiddlewaresServerFactory; } });
14
- const cannon_util_1 = require("./cannon.util");
15
- Object.defineProperty(exports, "runCannon", { enumerable: true, get: function () { return cannon_util_1.runCannon; } });
16
- Object.defineProperty(exports, "runCannonScript", { enumerable: true, get: function () { return cannon_util_1.runCannonScript; } });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./bench.model"), exports);
5
+ tslib_1.__exportStar(require("./bench.profles"), exports);
6
+ tslib_1.__exportStar(require("./bench.util"), exports);
7
+ tslib_1.__exportStar(require("./cannon.model"), exports);
8
+ tslib_1.__exportStar(require("./cannon.profiles"), exports);
9
+ tslib_1.__exportStar(require("./cannon.util"), exports);
package/package.json CHANGED
@@ -34,7 +34,7 @@
34
34
  "engines": {
35
35
  "node": ">=18.12.0"
36
36
  },
37
- "version": "2.1.0",
37
+ "version": "3.0.0",
38
38
  "description": "Benchmarking library, based on Benchmark.js and Autocannon",
39
39
  "author": "Natural Cycles Team",
40
40
  "license": "MIT"