overtake 1.3.0 → 1.3.1
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/README.md +49 -31
- package/context7.json +4 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -112,10 +112,12 @@ benchmark('local', () => 1)
|
|
|
112
112
|
|
|
113
113
|
// Programmatic usage – provide baseUrl
|
|
114
114
|
const suite = new Benchmark('local');
|
|
115
|
-
suite
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
115
|
+
suite
|
|
116
|
+
.target('helper', async () => {
|
|
117
|
+
const { helper } = await import('./helpers.js');
|
|
118
|
+
return { helper };
|
|
119
|
+
})
|
|
120
|
+
.measure('use helper', ({ helper }) => helper());
|
|
119
121
|
await suite.execute({ baseUrl: import.meta.url });
|
|
120
122
|
```
|
|
121
123
|
|
|
@@ -127,16 +129,15 @@ When using `npx overtake`, a global `benchmark` function is provided:
|
|
|
127
129
|
|
|
128
130
|
```typescript
|
|
129
131
|
// benchmark.ts - No imports needed!
|
|
130
|
-
benchmark('small', () => generateSmallData())
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
});
|
|
132
|
+
const suite = benchmark('small', () => generateSmallData()).feed('large', () => generateLargeData());
|
|
133
|
+
|
|
134
|
+
suite.target('algorithm A').measure('process', (_, input) => {
|
|
135
|
+
processA(input);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
suite.target('algorithm B').measure('process', (_, input) => {
|
|
139
|
+
processB(input);
|
|
140
|
+
});
|
|
140
141
|
```
|
|
141
142
|
|
|
142
143
|
```bash
|
|
@@ -171,21 +172,32 @@ printTableReports(reports);
|
|
|
171
172
|
|
|
172
173
|
```typescript
|
|
173
174
|
// Create with initial feed
|
|
174
|
-
benchmark('initial data', () => data)
|
|
175
|
-
.feed('more data', () => moreData) // Add more datasets
|
|
175
|
+
const suite = benchmark('initial data', () => data).feed('more data', () => moreData); // Add more datasets
|
|
176
176
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
})
|
|
177
|
+
// Define what to compare
|
|
178
|
+
suite.target('implementation A').measure('operation', (ctx, input) => {
|
|
179
|
+
/* ... */
|
|
180
|
+
});
|
|
182
181
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
});
|
|
182
|
+
suite.target('implementation B').measure('operation', (ctx, input) => {
|
|
183
|
+
/* ... */
|
|
184
|
+
});
|
|
187
185
|
```
|
|
188
186
|
|
|
187
|
+
### Method Chaining Reference
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
benchmark(name, feedFn) -> Benchmark
|
|
191
|
+
.feed(name, feedFn) -> Benchmark
|
|
192
|
+
.target(name, setup?) -> Target
|
|
193
|
+
.teardown(fn) -> Target
|
|
194
|
+
.measure(name, fn) -> Measure
|
|
195
|
+
.pre(fn) -> Measure
|
|
196
|
+
.post(fn) -> Measure
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Note: `.measure()` returns `Measure`, not `Benchmark`. To add multiple targets, call `suite.target()` separately for each.
|
|
200
|
+
|
|
189
201
|
### Targets with Setup
|
|
190
202
|
|
|
191
203
|
```typescript
|
|
@@ -243,12 +255,18 @@ sumBenchmark.target('reduce').measure('sum', (_, numbers) => {
|
|
|
243
255
|
|
|
244
256
|
```typescript
|
|
245
257
|
// examples/imports.ts - Correct way to import local files
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
258
|
+
const suite = benchmark('local modules', () => testData);
|
|
259
|
+
|
|
260
|
+
suite
|
|
261
|
+
.target('local files', async () => {
|
|
262
|
+
const { join } = await import('node:path');
|
|
263
|
+
const modulePath = join(process.cwd(), './build/myModule.js');
|
|
264
|
+
const { myFunction } = await import(modulePath);
|
|
265
|
+
return { myFunction };
|
|
266
|
+
})
|
|
267
|
+
.measure('call function', ({ myFunction }, input) => {
|
|
268
|
+
myFunction(input);
|
|
269
|
+
});
|
|
252
270
|
```
|
|
253
271
|
|
|
254
272
|
**[📁 See all examples](./examples/):**
|
package/context7.json
ADDED