mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 12:30:44 +00:00
perf: reduce gateway startup overhead
This commit is contained in:
@@ -159,6 +159,10 @@ function hasFlag(flag: string): boolean {
|
||||
return process.argv.includes(flag);
|
||||
}
|
||||
|
||||
function hasHelpFlag(): boolean {
|
||||
return hasFlag("--help") || hasFlag("-h");
|
||||
}
|
||||
|
||||
function parseRepeatableFlag(flag: string): string[] {
|
||||
const values: string[] = [];
|
||||
for (let index = 0; index < process.argv.length; index += 1) {
|
||||
@@ -206,6 +210,28 @@ function parseOptions(): CliOptions {
|
||||
};
|
||||
}
|
||||
|
||||
function printUsage(): void {
|
||||
console.log(`OpenClaw Gateway startup benchmark
|
||||
|
||||
Usage:
|
||||
pnpm test:startup:gateway -- [options]
|
||||
node --import tsx scripts/bench-gateway-startup.ts [options]
|
||||
|
||||
Options:
|
||||
--case <id> Specific case id to run; repeatable
|
||||
--entry <path> Gateway CLI entry file (default: ${DEFAULT_ENTRY})
|
||||
--runs <n> Measured runs per case (default: ${DEFAULT_RUNS})
|
||||
--warmup <n> Warmup runs per case (default: ${DEFAULT_WARMUP})
|
||||
--timeout-ms <ms> Per-run timeout (default: ${DEFAULT_TIMEOUT_MS})
|
||||
--output <path> Write machine-readable JSON to a file
|
||||
--json Emit machine-readable JSON
|
||||
--help, -h Show this text
|
||||
|
||||
Case ids:
|
||||
${GATEWAY_CASES.map((benchCase) => `${benchCase.id} (${benchCase.name})`).join("\n ")}
|
||||
`);
|
||||
}
|
||||
|
||||
function median(values: number[]): number {
|
||||
const sorted = [...values].toSorted((a, b) => a - b);
|
||||
const middle = Math.floor(sorted.length / 2);
|
||||
@@ -796,6 +822,11 @@ function printResult(result: CaseResult): void {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
if (hasHelpFlag()) {
|
||||
printUsage();
|
||||
return;
|
||||
}
|
||||
|
||||
const options = parseOptions();
|
||||
const results: CaseResult[] = [];
|
||||
for (const benchCase of options.cases) {
|
||||
|
||||
Reference in New Issue
Block a user