Skip to content

Commit 434d07f

Browse files
refactor!: remove useless benchmark todos (#118)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
1 parent 46fbd0c commit 434d07f

File tree

5 files changed

+1
-62
lines changed

5 files changed

+1
-62
lines changed

README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ bench
4545
await new Promise((r) => setTimeout(r, 1)); // we wait 1ms :)
4646
console.log('I am slower');
4747
})
48-
.todo('unimplemented bench');
4948

5049
await bench.warmup(); // make results more reliable, ref: https://github.com/tinylibs/tinybench/pull/50
5150
await bench.run();
@@ -59,15 +58,6 @@ console.table(bench.table());
5958
// │ 0 │ 'faster task' │ '38,832' │ 25751.297631307978 │ '±3.48%' │ '22016.49999997812±5.5000000145' │ 3884 │
6059
// │ 1 │ 'slower task' │ '669' │ 1493338.567164177 │ '±5.98%' │ '1445076.0000000286' │ 67 │
6160
// └─────────┴───────────────┴──────────┴──────────────────────┴──────────┴──────────────────────────────────┴─────────┘
62-
63-
console.table(bench.table((task) => ({ 'Task name': task.name })));
64-
65-
// Output:
66-
// ┌─────────┬───────────────────────┐
67-
// │ (index) │ Task name │
68-
// ├─────────┼───────────────────────┤
69-
// │ 0 │ 'unimplemented bench' │
70-
// └─────────┴───────────────────────┘
7161
```
7262

7363
The `add` method accepts a task name and a task function, so it can benchmark
@@ -157,8 +147,6 @@ export type Hook = (task: Task, mode: 'warmup' | 'run') => void | Promise<void>;
157147
- `get results(): (TaskResult | undefined)[]`: (getter) tasks results as an array
158148
- `get tasks(): Task[]`: (getter) tasks as an array
159149
- `getTask(name: string): Task | undefined`: get a task based on the name
160-
- `todo(name: string, fn?: Fn, opts: FnOptions)`: add a benchmark todo to the todo map
161-
- `get todos(): Task[]`: (getter) tasks todos as an array
162150

163151
### `Task`
164152

@@ -334,7 +322,6 @@ export type BenchEvents =
334322
| 'cycle' // when running each benchmark task gets done (cycle)
335323
| 'add' // when a Task gets added to the Bench
336324
| 'remove' // when a Task gets removed of the Bench
337-
| 'todo'; // when a todo Task gets added to the Bench
338325

339326
/**
340327
* task events

examples/src/simple.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ bench
1010
.add('slower task', async () => {
1111
await new Promise((r) => setTimeout(r, 1)); // we wait 1ms :)
1212
console.log('I am slower');
13-
})
14-
.todo('unimplemented bench');
13+
});
1514

1615
await bench.run();
1716

@@ -24,16 +23,3 @@ console.table(bench.table());
2423
// │ 0 │ 'faster task' │ '38,832' │ 25751.297631307978 │ '±3.48%' │ '22016.49999997812±5.5000000145' │ 3884 │
2524
// │ 1 │ 'slower task' │ '669' │ 1493338.567164177 │ '±5.98%' │ '1445076.0000000286' │ 67 │
2625
// └─────────┴───────────────┴──────────┴──────────────────────┴──────────┴──────────────────────────────────┴─────────┘
27-
28-
console.table(
29-
bench.todos.map(({ name }) => ({
30-
'Task name': name,
31-
})),
32-
);
33-
34-
// Output:
35-
// ┌─────────┬───────────────────────┐
36-
// │ (index) │ Task name │
37-
// ├─────────┼───────────────────────┤
38-
// │ 0 │ 'unimplemented bench' │
39-
// └─────────┴───────────────────────┘

src/bench.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ export default class Bench extends EventTarget {
2323
*/
2424
private readonly _tasks: Map<string, Task> = new Map();
2525

26-
private readonly _todos: Map<string, Task> = new Map();
27-
2826
/**
2927
* Executes tasks concurrently based on the specified concurrency mode.
3028
*
@@ -193,17 +191,6 @@ export default class Bench extends EventTarget {
193191
return this;
194192
}
195193

196-
/**
197-
* add a benchmark todo to the todo map
198-
*/
199-
// eslint-disable-next-line @typescript-eslint/no-empty-function
200-
todo(name: string, fn: Fn = () => {}, opts: FnOptions = {}) {
201-
const task = new Task(this, name, fn, opts);
202-
this._todos.set(name, task);
203-
this.dispatchEvent(createBenchEvent('todo', task));
204-
return this;
205-
}
206-
207194
/**
208195
* remove a benchmark task from the task map
209196
*/
@@ -268,10 +255,6 @@ export default class Bench extends EventTarget {
268255
return [...this._tasks.values()];
269256
}
270257

271-
get todos(): Task[] {
272-
return [...this._todos.values()];
273-
}
274-
275258
/**
276259
* get a task based on the task name
277260
*/

src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ export type BenchEvents =
156156
| 'cycle' // when running each benchmark task gets done (cycle)
157157
| 'add' // when a Task gets added to the Bench
158158
| 'remove' // when a Task gets removed of the Bench
159-
| 'todo'; // when a todo Task gets added to the Bench
160159

161160
export type Hook = (task: Task, mode: 'warmup' | 'run') => void | Promise<void>;
162161

@@ -173,7 +172,6 @@ export interface BenchEventsMap{
173172
remove: TaskEventListener
174173
cycle: TaskEventListener
175174
error: TaskEventListener
176-
todo: TaskEventListener
177175
}
178176

179177
/**

test/index.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -187,21 +187,6 @@ test('events order 2', async () => {
187187
await new Promise((resolve) => setTimeout(resolve, 150));
188188
});
189189

190-
test('todo event', async () => {
191-
const bench = new Bench({ time: 50 });
192-
193-
let todoTask: Task;
194-
bench.addEventListener('todo', ({ task }) => {
195-
todoTask = task;
196-
});
197-
198-
bench.todo('unimplemented bench');
199-
200-
await bench.run();
201-
202-
expect(todoTask!.name).toBe('unimplemented bench');
203-
});
204-
205190
test('error event', async () => {
206191
const bench = new Bench({ time: 50 });
207192
const err = new Error();

0 commit comments

Comments
 (0)