overtake 1.0.0-rc.2 → 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.
- package/build/cli.cjs +7 -7
- package/build/cli.cjs.map +1 -1
- package/build/cli.js +1 -1
- package/build/cli.js.map +1 -1
- package/build/index.cjs +228 -11
- package/build/index.cjs.map +1 -1
- package/build/index.d.ts +65 -3
- package/build/index.js +187 -1
- package/build/index.js.map +1 -1
- package/build/reporter.cjs +1 -1
- package/build/reporter.cjs.map +1 -1
- package/build/reporter.js +1 -1
- package/build/reporter.js.map +1 -1
- package/examples/array-copy.ts +17 -0
- package/package.json +1 -1
- package/src/cli.ts +2 -2
- package/src/index.ts +232 -3
- package/src/reporter.ts +1 -1
- package/build/__tests__/runner.d.ts +0 -1
- package/build/benchmark.cjs +0 -237
- package/build/benchmark.cjs.map +0 -1
- package/build/benchmark.d.ts +0 -64
- package/build/benchmark.js +0 -189
- package/build/benchmark.js.map +0 -1
- package/overtakes/array-copy.md +0 -80
- package/overtakes/array-delete-element.md +0 -44
- package/overtakes/async.md +0 -25
- package/overtakes/class-vs-function.md +0 -31
- package/overtakes/postgres-vs-mongo.md +0 -55
- package/src/__tests__/runner.ts +0 -34
- package/src/benchmark.ts +0 -231
package/build/benchmark.cjs
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
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
|
-
});
|
|
183
|
-
}
|
|
184
|
-
targetReport.measures.push(measureReport);
|
|
185
|
-
}
|
|
186
|
-
reports.push(targetReport);
|
|
187
|
-
}
|
|
188
|
-
await executor.drain();
|
|
189
|
-
executor.kill();
|
|
190
|
-
return reports;
|
|
191
|
-
}
|
|
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
|
-
};
|
|
236
|
-
|
|
237
|
-
//# sourceMappingURL=benchmark.cjs.map
|
package/build/benchmark.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/benchmark.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\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":";;;;;;;;;;;IAMaA,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;;;wBA7MQ;6BAC2C;0BAC8C;AAEvG,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,QAAAA;aACAC,MAAAA;IACN;AACL;AAEO,MAAMb;IACX,CAAA,GAAI,CAAmC;IAEvCS,YAAYK,GAAqC,CAAE;QACjD,IAAI,CAAC,CAAA,GAAI,GAAGA;IACd;IAEAJ,IAAIK,EAA4B,EAA6B;QAC3D,IAAI,CAAC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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/benchmark.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { ExecutorOptions, ExecutorReport } from './executor.js';
|
|
2
|
-
import { MaybePromise, StepFn, SetupFn, TeardownFn, FeedFn, ReportType, ReportTypeList } from './types.js';
|
|
3
|
-
export declare const DEFAULT_WORKERS: number;
|
|
4
|
-
export declare const AsyncFunction: Function;
|
|
5
|
-
export interface TargetReport<R extends ReportTypeList> {
|
|
6
|
-
target: string;
|
|
7
|
-
measures: MeasureReport<R>[];
|
|
8
|
-
}
|
|
9
|
-
export interface MeasureReport<R extends ReportTypeList> {
|
|
10
|
-
measure: string;
|
|
11
|
-
feeds: FeedReport<R>[];
|
|
12
|
-
}
|
|
13
|
-
export interface FeedReport<R extends ReportTypeList> {
|
|
14
|
-
feed: string;
|
|
15
|
-
data: ExecutorReport<R>;
|
|
16
|
-
}
|
|
17
|
-
export declare const DEFAULT_REPORT_TYPES: readonly ["ops"];
|
|
18
|
-
export type DefaultReportTypes = (typeof DEFAULT_REPORT_TYPES)[number];
|
|
19
|
-
export declare class MeasureContext<TContext, TInput> {
|
|
20
|
-
title: string;
|
|
21
|
-
run: StepFn<TContext, TInput>;
|
|
22
|
-
pre?: StepFn<TContext, TInput>;
|
|
23
|
-
post?: StepFn<TContext, TInput>;
|
|
24
|
-
constructor(title: string, run: StepFn<TContext, TInput>);
|
|
25
|
-
}
|
|
26
|
-
export declare class Measure<TContext, TInput> {
|
|
27
|
-
#private;
|
|
28
|
-
constructor(ctx: MeasureContext<TContext, TInput>);
|
|
29
|
-
pre(fn: StepFn<TContext, TInput>): Measure<TContext, TInput>;
|
|
30
|
-
post(fn: StepFn<TContext, TInput>): Measure<TContext, TInput>;
|
|
31
|
-
}
|
|
32
|
-
export declare class TargetContext<TContext, TInput> {
|
|
33
|
-
readonly title: string;
|
|
34
|
-
readonly setup?: SetupFn<MaybePromise<TContext>> | undefined;
|
|
35
|
-
teardown?: TeardownFn<TContext>;
|
|
36
|
-
measures: MeasureContext<TContext, TInput>[];
|
|
37
|
-
constructor(title: string, setup?: SetupFn<MaybePromise<TContext>> | undefined);
|
|
38
|
-
}
|
|
39
|
-
export declare class Target<TContext, TInput> {
|
|
40
|
-
#private;
|
|
41
|
-
constructor(ctx: TargetContext<TContext, TInput>);
|
|
42
|
-
teardown(fn: TeardownFn<TContext>): Target<TContext, TInput>;
|
|
43
|
-
measure(title: string, run: StepFn<TContext, TInput>): Measure<TContext, TInput>;
|
|
44
|
-
}
|
|
45
|
-
export declare class FeedContext<TInput> {
|
|
46
|
-
readonly title: string;
|
|
47
|
-
readonly fn?: FeedFn<TInput> | undefined;
|
|
48
|
-
constructor(title: string, fn?: FeedFn<TInput> | undefined);
|
|
49
|
-
}
|
|
50
|
-
export declare class Benchmark<TInput> {
|
|
51
|
-
#private;
|
|
52
|
-
static create(title: string): Benchmark<void>;
|
|
53
|
-
static create<I>(title: string, fn: FeedFn<I>): Benchmark<I>;
|
|
54
|
-
constructor(title: string);
|
|
55
|
-
constructor(title: string, fn: FeedFn<TInput>);
|
|
56
|
-
feed(title: string): Benchmark<TInput | void>;
|
|
57
|
-
feed<I>(title: string, fn: FeedFn<I>): Benchmark<TInput | I>;
|
|
58
|
-
target<TContext>(title: string): Target<void, TInput>;
|
|
59
|
-
target<TContext>(title: string, setup: SetupFn<Awaited<TContext>>): Target<TContext, TInput>;
|
|
60
|
-
execute<R extends readonly ReportType[] = typeof DEFAULT_REPORT_TYPES>({ workers, warmupCycles, maxCycles, minCycles, absThreshold, relThreshold, reportTypes, }: ExecutorOptions<R>): Promise<TargetReport<R>[]>;
|
|
61
|
-
}
|
|
62
|
-
export declare const printSimpleReports: <R extends ReportTypeList>(reports: TargetReport<R>[]) => void;
|
|
63
|
-
export declare const printTableReports: <R extends ReportTypeList>(reports: TargetReport<R>[]) => void;
|
|
64
|
-
export declare const printJSONReports: <R extends ReportTypeList>(reports: TargetReport<R>[], padding?: number) => void;
|
package/build/benchmark.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { cpus } from 'node:os';
|
|
2
|
-
import { createExecutor } from "./executor.js";
|
|
3
|
-
import { DEFAULT_CYCLES } from "./types.js";
|
|
4
|
-
export const DEFAULT_WORKERS = cpus().length;
|
|
5
|
-
export const AsyncFunction = (async ()=>{}).constructor;
|
|
6
|
-
export const DEFAULT_REPORT_TYPES = [
|
|
7
|
-
'ops'
|
|
8
|
-
];
|
|
9
|
-
export class MeasureContext {
|
|
10
|
-
title;
|
|
11
|
-
run;
|
|
12
|
-
pre;
|
|
13
|
-
post;
|
|
14
|
-
constructor(title, run){
|
|
15
|
-
this.title = title;
|
|
16
|
-
this.run = run;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export class Measure {
|
|
20
|
-
#ctx;
|
|
21
|
-
constructor(ctx){
|
|
22
|
-
this.#ctx = ctx;
|
|
23
|
-
}
|
|
24
|
-
pre(fn) {
|
|
25
|
-
this.#ctx.pre = fn;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
post(fn) {
|
|
29
|
-
this.#ctx.post = fn;
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export class TargetContext {
|
|
34
|
-
title;
|
|
35
|
-
setup;
|
|
36
|
-
teardown;
|
|
37
|
-
measures;
|
|
38
|
-
constructor(title, setup){
|
|
39
|
-
this.title = title;
|
|
40
|
-
this.setup = setup;
|
|
41
|
-
this.measures = [];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
export class Target {
|
|
45
|
-
#ctx;
|
|
46
|
-
constructor(ctx){
|
|
47
|
-
this.#ctx = ctx;
|
|
48
|
-
}
|
|
49
|
-
teardown(fn) {
|
|
50
|
-
this.#ctx.teardown = fn;
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
measure(title, run) {
|
|
54
|
-
const measure = new MeasureContext(title, run);
|
|
55
|
-
this.#ctx.measures.push(measure);
|
|
56
|
-
return new Measure(measure);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export class FeedContext {
|
|
60
|
-
title;
|
|
61
|
-
fn;
|
|
62
|
-
constructor(title, fn){
|
|
63
|
-
this.title = title;
|
|
64
|
-
this.fn = fn;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
export class Benchmark {
|
|
68
|
-
#targets = [];
|
|
69
|
-
#feeds = [];
|
|
70
|
-
#executed = false;
|
|
71
|
-
static create(title, fn) {
|
|
72
|
-
if (fn) {
|
|
73
|
-
return new Benchmark(title, fn);
|
|
74
|
-
} else {
|
|
75
|
-
return new Benchmark(title);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
constructor(title, fn){
|
|
79
|
-
if (fn) {
|
|
80
|
-
this.feed(title, fn);
|
|
81
|
-
} else {
|
|
82
|
-
this.feed(title);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
feed(title, fn) {
|
|
86
|
-
const self = this;
|
|
87
|
-
self.#feeds.push(fn ? new FeedContext(title, fn) : new FeedContext(title));
|
|
88
|
-
return self;
|
|
89
|
-
}
|
|
90
|
-
target(title, setup) {
|
|
91
|
-
const target = new TargetContext(title, setup);
|
|
92
|
-
this.#targets.push(target);
|
|
93
|
-
return new Target(target);
|
|
94
|
-
}
|
|
95
|
-
async execute({ workers = DEFAULT_WORKERS, warmupCycles = 20, maxCycles = DEFAULT_CYCLES, minCycles = 50, absThreshold = 1_000, relThreshold = 0.02, reportTypes = DEFAULT_REPORT_TYPES }) {
|
|
96
|
-
if (this.#executed) {
|
|
97
|
-
throw new Error("Benchmark is executed and can't be reused");
|
|
98
|
-
}
|
|
99
|
-
this.#executed = true;
|
|
100
|
-
const executor = createExecutor({
|
|
101
|
-
workers,
|
|
102
|
-
warmupCycles,
|
|
103
|
-
maxCycles,
|
|
104
|
-
minCycles,
|
|
105
|
-
absThreshold,
|
|
106
|
-
relThreshold,
|
|
107
|
-
reportTypes
|
|
108
|
-
});
|
|
109
|
-
const reports = [];
|
|
110
|
-
for (const target of this.#targets){
|
|
111
|
-
const targetReport = {
|
|
112
|
-
target: target.title,
|
|
113
|
-
measures: []
|
|
114
|
-
};
|
|
115
|
-
for (const measure of target.measures){
|
|
116
|
-
const measureReport = {
|
|
117
|
-
measure: measure.title,
|
|
118
|
-
feeds: []
|
|
119
|
-
};
|
|
120
|
-
for (const feed of this.#feeds){
|
|
121
|
-
const data = await feed.fn?.();
|
|
122
|
-
executor.push({
|
|
123
|
-
setup: target.setup,
|
|
124
|
-
teardown: target.teardown,
|
|
125
|
-
pre: measure.pre,
|
|
126
|
-
run: measure.run,
|
|
127
|
-
post: measure.post,
|
|
128
|
-
data
|
|
129
|
-
}).then((data)=>{
|
|
130
|
-
measureReport.feeds.push({
|
|
131
|
-
feed: feed.title,
|
|
132
|
-
data
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
targetReport.measures.push(measureReport);
|
|
137
|
-
}
|
|
138
|
-
reports.push(targetReport);
|
|
139
|
-
}
|
|
140
|
-
await executor.drain();
|
|
141
|
-
executor.kill();
|
|
142
|
-
return reports;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
export const printSimpleReports = (reports)=>{
|
|
146
|
-
for (const report of reports){
|
|
147
|
-
for (const { measure, feeds } of report.measures){
|
|
148
|
-
console.group('\n', report.target, measure);
|
|
149
|
-
for (const { feed, data } of feeds){
|
|
150
|
-
const output = Object.entries(data).map(([key, report])=>`${key}: ${report.toString()}`).join('; ');
|
|
151
|
-
console.log(feed, output);
|
|
152
|
-
}
|
|
153
|
-
console.groupEnd();
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
export const printTableReports = (reports)=>{
|
|
158
|
-
for (const report of reports){
|
|
159
|
-
for (const { measure, feeds } of report.measures){
|
|
160
|
-
console.log('\n', report.target, measure);
|
|
161
|
-
const table = {};
|
|
162
|
-
for (const { feed, data } of feeds){
|
|
163
|
-
table[feed] = Object.fromEntries(Object.entries(data).map(([key, report])=>[
|
|
164
|
-
key,
|
|
165
|
-
report.toString()
|
|
166
|
-
]));
|
|
167
|
-
}
|
|
168
|
-
console.table(table);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
export const printJSONReports = (reports, padding)=>{
|
|
173
|
-
const output = {};
|
|
174
|
-
for (const report of reports){
|
|
175
|
-
for (const { measure, feeds } of report.measures){
|
|
176
|
-
const row = {};
|
|
177
|
-
for (const { feed, data } of feeds){
|
|
178
|
-
row[feed] = Object.fromEntries(Object.entries(data).map(([key, report])=>[
|
|
179
|
-
key,
|
|
180
|
-
report.toString()
|
|
181
|
-
]));
|
|
182
|
-
}
|
|
183
|
-
output[`${report.target} ${measure}`] = row;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
console.log(JSON.stringify(output, null, padding));
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
//# sourceMappingURL=benchmark.js.map
|
package/build/benchmark.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/benchmark.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\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":["cpus","createExecutor","DEFAULT_CYCLES","DEFAULT_WORKERS","length","AsyncFunction","constructor","DEFAULT_REPORT_TYPES","MeasureContext","pre","post","title","run","Measure","ctx","fn","TargetContext","teardown","measures","setup","Target","measure","push","FeedContext","Benchmark","create","feed","self","target","execute","workers","warmupCycles","maxCycles","minCycles","absThreshold","relThreshold","reportTypes","Error","executor","reports","targetReport","measureReport","feeds","data","then","drain","kill","printSimpleReports","report","console","group","output","Object","entries","map","key","toString","join","log","groupEnd","printTableReports","table","fromEntries","printJSONReports","padding","row","JSON","stringify"],"mappings":"AAAA,SAASA,IAAI,QAAQ,UAAU;AAC/B,SAASC,cAAc,QAAyC,gBAAgB;AAChF,SAAwFC,cAAc,QAAQ,aAAa;AAE3H,OAAO,MAAMC,kBAAkBH,OAAOI,MAAM,CAAC;AAE7C,OAAO,MAAMC,gBAAgB,AAAC,CAAA,WAAa,CAAA,EAAGC,WAAW,CAAC;AAiB1D,OAAO,MAAMC,uBAAuB;IAAC;CAAM,CAAU;AAGrD,OAAO,MAAMC;;;IACJC,IAA+B;IAC/BC,KAAgC;IAEvCJ,YACE,AAAOK,KAAa,EACpB,AAAOC,GAA6B,CACpC;aAFOD,QAAAA;aACAC,MAAAA;IACN;AACL;AAEA,OAAO,MAAMC;IACX,CAAA,GAAI,CAAmC;IAEvCP,YAAYQ,GAAqC,CAAE;QACjD,IAAI,CAAC,CAAA,GAAI,GAAGA;IACd;IAEAL,IAAIM,EAA4B,EAA6B;QAC3D,IAAI,CAAC,CAAA,GAAI,CAACN,GAAG,GAAGM;QAChB,OAAO,IAAI;IACb;IACAL,KAAKK,EA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,CAACC,KAAKP,OAAO,GAAK;wBAACO;wBAAKP,OAAOQ,QAAQ;qBAAG;YACvG;YACAP,QAAQY,KAAK,CAACA;QAChB;IACF;AACF,EAAE;AAEF,OAAO,MAAME,mBAAmB,CAA2BxB,SAA4ByB;IACrF,MAAMb,SAAS,CAAC;IAChB,KAAK,MAAMH,UAAUT,QAAS;QAC5B,KAAK,MAAM,EAAElB,OAAO,EAAEqB,KAAK,EAAE,IAAIM,OAAO9B,QAAQ,CAAE;YAChD,MAAM+C,MAAM,CAAC;YACb,KAAK,MAAM,EAAEvC,IAAI,EAAEiB,IAAI,EAAE,IAAID,MAAO;gBAClCuB,GAAG,CAACvC,KAAK,GAAG0B,OAAOU,WAAW,CAACV,OAAOC,OAAO,CAACV,MAAMW,GAAG,CAAC,CAAC,CAACC,KAAKP,OAAO,GAAK;wBAACO;wBAAKP,OAAOQ,QAAQ;qBAAG;YACrG;YACAL,MAAM,CAAC,GAAGH,OAAOpB,MAAM,CAAC,CAAC,EAAEP,SAAS,CAAC,GAAG4C;QAC1C;IACF;IACAhB,QAAQS,GAAG,CAACQ,KAAKC,SAAS,CAAChB,QAAQ,MAAMa;AAC3C,EAAE"}
|
package/overtakes/array-copy.md
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# Array copy methods
|
|
2
|
-
|
|
3
|
-
```
|
|
4
|
-
⭐ Script __benchmarks__/array-copy.js
|
|
5
|
-
⇶ Suite Array copy methods
|
|
6
|
-
➤ Perform 10 elements
|
|
7
|
-
✓ Measure 500000 slice
|
|
8
|
-
┌──────────┬──────────┬──────────┬──────────┬───────────┬────────┐
|
|
9
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
10
|
-
├──────────┼──────────┼──────────┼──────────┼───────────┼────────┤
|
|
11
|
-
│ 0.000059 │ 0.000065 │ 0.000105 │ 0.000241 │ 50.160222 │ 500000 │
|
|
12
|
-
└──────────┴──────────┴──────────┴──────────┴───────────┴────────┘
|
|
13
|
-
✓ Measure 500000 spread
|
|
14
|
-
┌──────────┬──────────┬──────────┬──────────┬──────────┬────────┐
|
|
15
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
16
|
-
├──────────┼──────────┼──────────┼──────────┼──────────┼────────┤
|
|
17
|
-
│ 0.000061 │ 0.000067 │ 0.000087 │ 0.000193 │ 44.70032 │ 500000 │
|
|
18
|
-
└──────────┴──────────┴──────────┴──────────┴──────────┴────────┘
|
|
19
|
-
✓ Measure 500000 concat
|
|
20
|
-
┌──────────┬──────────┬──────────┬──────────┬───────────┬────────┐
|
|
21
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
22
|
-
├──────────┼──────────┼──────────┼──────────┼───────────┼────────┤
|
|
23
|
-
│ 0.000061 │ 0.000068 │ 0.000119 │ 0.000234 │ 40.695219 │ 500000 │
|
|
24
|
-
└──────────┴──────────┴──────────┴──────────┴───────────┴────────┘
|
|
25
|
-
✓ Measure 500000 Array.from
|
|
26
|
-
┌──────────┬──────────┬──────────┬──────────┬───────────┬────────┐
|
|
27
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
28
|
-
├──────────┼──────────┼──────────┼──────────┼───────────┼────────┤
|
|
29
|
-
│ 0.000065 │ 0.000072 │ 0.000126 │ 0.000237 │ 50.390629 │ 500000 │
|
|
30
|
-
└──────────┴──────────┴──────────┴──────────┴───────────┴────────┘
|
|
31
|
-
✓ Measure 500000 for loop assign
|
|
32
|
-
┌──────────┬──────────┬──────────┬──────────┬───────────┬────────┐
|
|
33
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
34
|
-
├──────────┼──────────┼──────────┼──────────┼───────────┼────────┤
|
|
35
|
-
│ 0.000066 │ 0.000071 │ 0.000126 │ 0.000287 │ 43.803009 │ 500000 │
|
|
36
|
-
└──────────┴──────────┴──────────┴──────────┴───────────┴────────┘
|
|
37
|
-
✓ Measure 500000 for loop push
|
|
38
|
-
┌──────────┬──────────┬──────────┬──────────┬───────────┬────────┐
|
|
39
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
40
|
-
├──────────┼──────────┼──────────┼──────────┼───────────┼────────┤
|
|
41
|
-
│ 0.000065 │ 0.000072 │ 0.000142 │ 0.000284 │ 43.769935 │ 500000 │
|
|
42
|
-
└──────────┴──────────┴──────────┴──────────┴───────────┴────────┘
|
|
43
|
-
➤ Perform 1000 elements
|
|
44
|
-
✓ Measure 500000 slice
|
|
45
|
-
┌─────────┬──────────┬──────────┬──────────┬────────────┬────────┐
|
|
46
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
47
|
-
├─────────┼──────────┼──────────┼──────────┼────────────┼────────┤
|
|
48
|
-
│ 0.00011 │ 0.000182 │ 0.000371 │ 0.000601 │ 186.871627 │ 500000 │
|
|
49
|
-
└─────────┴──────────┴──────────┴──────────┴────────────┴────────┘
|
|
50
|
-
✓ Measure 500000 spread
|
|
51
|
-
┌──────────┬──────────┬──────────┬──────────┬────────────┬────────┐
|
|
52
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
53
|
-
├──────────┼──────────┼──────────┼──────────┼────────────┼────────┤
|
|
54
|
-
│ 0.000113 │ 0.000186 │ 0.000362 │ 0.000577 │ 186.106348 │ 500000 │
|
|
55
|
-
└──────────┴──────────┴──────────┴──────────┴────────────┴────────┘
|
|
56
|
-
✓ Measure 500000 concat
|
|
57
|
-
┌──────────┬──────────┬──────────┬──────────┬────────────┬────────┐
|
|
58
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
59
|
-
├──────────┼──────────┼──────────┼──────────┼────────────┼────────┤
|
|
60
|
-
│ 0.000116 │ 0.000199 │ 0.000445 │ 0.000772 │ 204.249913 │ 500000 │
|
|
61
|
-
└──────────┴──────────┴──────────┴──────────┴────────────┴────────┘
|
|
62
|
-
✓ Measure 500000 Array.from
|
|
63
|
-
┌──────────┬─────────┬──────────┬──────────┬────────────┬────────┐
|
|
64
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
65
|
-
├──────────┼─────────┼──────────┼──────────┼────────────┼────────┤
|
|
66
|
-
│ 0.000113 │ 0.00019 │ 0.000347 │ 0.000564 │ 190.512575 │ 500000 │
|
|
67
|
-
└──────────┴─────────┴──────────┴──────────┴────────────┴────────┘
|
|
68
|
-
✓ Measure 500000 for loop assign
|
|
69
|
-
┌──────────┬──────────┬──────────┬─────────┬────────────┬────────┐
|
|
70
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
71
|
-
├──────────┼──────────┼──────────┼─────────┼────────────┼────────┤
|
|
72
|
-
│ 0.002016 │ 0.002428 │ 0.003344 │ 0.00437 │ 1477.99805 │ 500000 │
|
|
73
|
-
└──────────┴──────────┴──────────┴─────────┴────────────┴────────┘
|
|
74
|
-
✓ Measure 500000 for loop push
|
|
75
|
-
┌──────────┬──────────┬──────────┬──────────┬─────────────┬────────┐
|
|
76
|
-
│ (index) │ med │ p95 │ p99 │ total │ count │
|
|
77
|
-
├──────────┼──────────┼──────────┼──────────┼─────────────┼────────┤
|
|
78
|
-
│ 0.002343 │ 0.002756 │ 0.003774 │ 0.006158 │ 1687.568837 │ 500000 │
|
|
79
|
-
└──────────┴──────────┴──────────┴──────────┴─────────────┴────────┘
|
|
80
|
-
```
|