-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(benchmark): run benchmark suites sequentially (#5444)
- Loading branch information
Showing
18 changed files
with
151 additions
and
71 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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,3 @@ | ||
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, | ||
}], | ||
}, | ||
}, | ||
}) | ||
export default defineConfig({}) |