Skip to content

Allow async computeds #59

@stephenh

Description

@stephenh

I'm using mitata to benchmark SQL/ORM performance, which I know is generally outside of its CPU microbenchmark focus, but so far it's working really well!

I would like to be able to reset the database tables before each run, just to make the SQL benchmarks easier to write b/c each iteration doesn't have to worry about conflicting with the ids/data written by the previous.

And, as like the existing computed properties feature, ideally this reset wouldn't count towards each iteration's actual benchmark time.

I thought the computed property API would do what I need:

    bench("sequential", function* () {
      yield {
        async [0]() {
          await sql`TRUNCATE tag CASCADE`;
        },
        async bench() {
          await sql.begin(async (sql) => {
            for (let i = 0; i < numStatements; i++) {
              await sql`INSERT INTO tag (name) VALUES (${`value-${nextTag++}`})`;
            }
          });
        },
      };
    });

But it looks like that the [0]() result is not awaited, which for the postgres.js query builder I'm using, means the SQL isn't actually executed (and even if it was executed, I'd want the bench function to only run after that promise had resolved).

If it's not too much out-of-scope for mitata's focus, this support for async input params (albeit I'm not really using it as an input param, but just an async beforeEach), would be great. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions