-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmitata+0.1.11.patch
77 lines (72 loc) · 2.16 KB
/
mitata+0.1.11.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
diff --git a/node_modules/mitata/src/cli.d.ts b/node_modules/mitata/src/cli.d.ts
index acd42b3..415130f 100644
--- a/node_modules/mitata/src/cli.d.ts
+++ b/node_modules/mitata/src/cli.d.ts
@@ -5,6 +5,8 @@ export function group(fn: () => void): void;
export function group(name: string, fn: () => void): void;
export function group(options: { name?: string, summary?: boolean }, fn: () => void): void;
+export function prepare(name: string, fn: () => any): void;
+
export function run(options?: {
avg?: boolean,
silent?: boolean,
diff --git a/node_modules/mitata/src/cli.mjs b/node_modules/mitata/src/cli.mjs
index 45be23e..651a206 100644
--- a/node_modules/mitata/src/cli.mjs
+++ b/node_modules/mitata/src/cli.mjs
@@ -32,6 +32,7 @@ export function bench(name, fn) {
time: 500,
warmup: true,
baseline: false,
+ hook: false,
async: AsyncFunction === fn.constructor,
});
};
@@ -47,10 +48,27 @@ export function baseline(name, fn) {
time: 500,
warmup: true,
baseline: true,
+ hook: false,
async: AsyncFunction === fn.constructor,
});
};
+export function prepare(name, fn) {
+ if ([Function, AsyncFunction].includes(name.constructor)) (fn = name, name = fn.name);
+ if (![Function, AsyncFunction].includes(fn.constructor)) throw new TypeError(`expected function, got ${fn.constructor.name}`);
+
+ benchmarks.push({
+ fn,
+ name,
+ group: g,
+ time: 500,
+ warmup: false,
+ baseline: false,
+ hook: true,
+ async: AsyncFunction === fn.constructor,
+ });
+}
+
let _print;
try {
@@ -243,6 +261,11 @@ export async function run(opts = {}) {
_f = true;
try {
+ if (b.hook) {
+ await b.fn();
+ continue;
+ }
+
b.stats = (await measure(b.fn, {})).stats;
if (!json) log(table.benchmark(b.name, b.stats, opts));
}
@@ -267,6 +290,11 @@ export async function run(opts = {}) {
if (group !== b.group) continue;
try {
+ if (b.hook) {
+ await b.fn();
+ continue;
+ }
+
b.stats = (await measure(b.fn, {})).stats;
if (!json) log(table.benchmark(b.name, b.stats, opts));
}