tinybench
tinybench copied to clipboard
Idea
We can load childProcess like this
import createBenchEvent from "./event";
import { isESM, isNode, taskIdFromEnv } from "./utils";
import Bench from "./bench";
import Task from "./task";
let childProcess = null;
// in bench.ts
async run() {
this.dispatchEvent(createBenchEvent('start'));
const values: Task[] = [];
if (!isNode) {
for (const task of [...this._tasks.values()]) {
if (this.signal?.aborted) values.push(task);
else values.push(await task.run());
}
} else {
const taskId = taskIdFromEnv();
if (taskId !== -1) {
const task = this.getTask(taskId);
if (task) {
await task.run();
return JSON.stringify(task.result);
}
return [];
} else {
// @ts-ignore
childProcess ??= isESM ? await import('node:child_process') : require('node:child_process');
for (const task of [...this._tasks.values()]) {
const result = childProcess.execSync(`TINYBENCH_TASK_ID=${task.id} ${process.argv.join(' ')}`, { env: process.env });
task.result = JSON.parse(result.toString());
}
}
}
I cant get it to work properly. :D
Maybe somebody else has to take over.
Do you consider the possibility that tasks can be added in a different order at each launch?
so the id will be different on each run
Any summary on this PR?
@Uzlopak @sirenkovladd: I do not see the added value of having a todo primitive. I will remove it.
See #120