Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Idea #62

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Idea #62

wants to merge 3 commits into from

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Oct 23, 2023

No description provided.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 23, 2023

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());
        }
      }
    }

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Oct 23, 2023

I cant get it to work properly. :D

Maybe somebody else has to take over.

@sirenkovladd
Copy link
Member

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

src/bench.ts Outdated Show resolved Hide resolved
src/bench.ts Outdated Show resolved Hide resolved
src/task.ts Show resolved Hide resolved
src/bench.ts Outdated Show resolved Hide resolved
@sirenkovladd sirenkovladd self-requested a review November 5, 2023 06:21
@sirenkovladd sirenkovladd self-assigned this Nov 5, 2023
@Aslemammad
Copy link
Member

Any summary on this PR?

@jerome-benoit
Copy link
Collaborator

@Uzlopak @sirenkovladd: I do not see the added value of having a todo primitive. I will remove it.

jerome-benoit added a commit to jerome-benoit/tinybench that referenced this pull request Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants