-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(benchmark): run benchmark suites sequentially #5444
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1dd47b9
fix(benchmark): run benchmark suites sequentially
hi-ogawa 9016b3f
test: add test
hi-ogawa 1c7e5c5
test: refactor
hi-ogawa 323219a
Merge branch 'main' into fix-bench-sequential
hi-ogawa b5e299f
test: move to benchmark2
hi-ogawa 9fbaf46
test: move to test/benchmark
hi-ogawa e34c1b4
chore: comment
hi-ogawa 3d962bc
Merge branch 'main' into fix-bench-sequential
hi-ogawa 77bf5a2
chore: cleanup config
hi-ogawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { defineConfig } from 'vitest/config' | ||
|
|
||
| export default defineConfig({}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { bench, describe } from "vitest" | ||
| import { appendLog, benchOptions, sleepBench } from "./helper"; | ||
|
|
||
| bench("B1", async () => { | ||
| await appendLog("F1 / B1") | ||
| await sleepBench(); | ||
| }, benchOptions) | ||
|
|
||
| describe("S1", () => { | ||
| bench("B1", async () => { | ||
| await appendLog("F1 / S1 / B1") | ||
| await sleepBench(); | ||
| }, benchOptions) | ||
|
|
||
| bench("B2", async () => { | ||
| await appendLog("F1 / S1 / B2") | ||
| await sleepBench(); | ||
| }, benchOptions) | ||
| }) | ||
|
|
||
| describe("S2", () => { | ||
| bench("B1", async () => { | ||
| await appendLog("F1 / S2 / B1") | ||
| await sleepBench(); | ||
| }, benchOptions) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { bench, describe } from "vitest" | ||
| import { appendLog, benchOptions, sleepBench } from "./helper"; | ||
|
|
||
| describe("S1", () => { | ||
| bench("B1", async () => { | ||
| await appendLog("F2 / S1 / B1") | ||
| await sleepBench(); | ||
| }, benchOptions) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import fs from "node:fs"; | ||
|
|
||
| const SLEEP_BENCH_MS = Number(process.env["SLEEP_BENCH_MS"] || 10); | ||
| const BENCH_ITERATIONS = Number(process.env["BENCH_ITERATIONS"] || 3); | ||
|
|
||
| export const sleepBench = () => new Promise(resolve => setTimeout(resolve, SLEEP_BENCH_MS)) | ||
|
|
||
| export const testLogFile = new URL("./test.log", import.meta.url); | ||
|
|
||
| export async function appendLog(data: string) { | ||
| await fs.promises.appendFile(testLogFile, data + "\n"); | ||
| } | ||
|
|
||
| export const benchOptions = { | ||
| time: 0, | ||
| iterations: BENCH_ITERATIONS, | ||
| warmupIterations: 0, | ||
| warmupTime: 0, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import fs from "node:fs"; | ||
| import { testLogFile } from "./helper"; | ||
|
|
||
| export default async function setup() { | ||
| await fs.promises.rm(testLogFile, { force: true }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { defineConfig } from "vitest/config" | ||
|
|
||
| // to see the difference better, increase sleep time and iterations e.g. by | ||
| // SLEEP_BENCH_MS=100 pnpm -C test/benchmark test bench -- --root fixtures/sequential --fileParallelism | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| globalSetup: ["./setup.ts"] | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
|
||
| exports[`sequential 1`] = ` | ||
| "F1 / S1 / B1 | ||
| F1 / S1 / B1 | ||
| F1 / S1 / B1 | ||
| F1 / S1 / B2 | ||
| F1 / S1 / B2 | ||
| F1 / S1 / B2 | ||
| F1 / S2 / B1 | ||
| F1 / S2 / B1 | ||
| F1 / S2 / B1 | ||
| F1 / B1 | ||
| F1 / B1 | ||
| F1 / B1 | ||
| F2 / S1 / B1 | ||
| F2 / S1 / B1 | ||
| F2 / S1 / B1 | ||
| " | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import fs from 'node:fs' | ||
| import { expect, it } from 'vitest' | ||
| import * as pathe from 'pathe' | ||
| import { runVitest } from '../../test-utils' | ||
|
|
||
| it('basic', { timeout: 60_000 }, async () => { | ||
| const root = pathe.join(import.meta.dirname, '../fixtures/basic') | ||
| const benchFile = pathe.join(root, 'bench.json') | ||
| fs.rmSync(benchFile, { force: true }) | ||
|
|
||
| await runVitest({ | ||
| root, | ||
| allowOnly: true, | ||
| benchmark: { | ||
| reporters: 'json', | ||
| outputFile: 'bench.json', | ||
| }, | ||
| }, [], 'benchmark') | ||
|
|
||
| const benchResult = await fs.promises.readFile(benchFile, 'utf-8') | ||
| const resultJson = JSON.parse(benchResult) | ||
|
|
||
| expect(Object.keys(resultJson.testResults)).toEqual( | ||
| expect.arrayContaining([ | ||
| 'sort', | ||
| 'timeout', | ||
| 'a0', | ||
| 'c1', | ||
| 'a2', | ||
| 'b3', | ||
| 'b4', | ||
| ]), | ||
| ) | ||
|
|
||
| const skipped = ['skip', 's0', 's1', 's2', 's3', 'sb4', 's4', 'unimplemented suite', 'unimplemented test'] | ||
| for (const b of skipped) | ||
| expect(benchResult).not.toContain(b) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import fs from 'node:fs' | ||
| import { expect, it } from 'vitest' | ||
| import * as pathe from 'pathe' | ||
| import { runVitest } from '../../test-utils' | ||
|
|
||
| it('sequential', async () => { | ||
| const root = pathe.join(import.meta.dirname, '../fixtures/sequential') | ||
| await runVitest({ root }, [], 'benchmark') | ||
| const testLog = await fs.promises.readFile(pathe.join(root, 'test.log'), 'utf-8') | ||
| expect(testLog).toMatchSnapshot() | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,7 @@ | ||
| import { defineConfig } from 'vitest/config' | ||
|
|
||
| function noop() {} | ||
|
|
||
| export default defineConfig({ | ||
| test: { | ||
| update: false, | ||
| allowOnly: true, | ||
| benchmark: { | ||
| outputFile: './bench.json', | ||
| reporters: ['json', { | ||
| onInit: noop, | ||
| onPathsCollected: noop, | ||
| onCollected: noop, | ||
| onFinished: noop, | ||
| onTaskUpdate: noop, | ||
| onTestRemoved: noop, | ||
| onWatcherStart: noop, | ||
| onWatcherRerun: noop, | ||
| onServerRestart: noop, | ||
| onUserConsoleLog: noop, | ||
| }], | ||
| }, | ||
| fileParallelism: false, | ||
| }, | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.