Skip to content
Myr

ci: simplify HTTP benchmark implementation (#4226)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* refactor: simplify HTTP benchmark with relative comparison - Move HTTP benchmarking from perf-measures to benchmarks/http-server - Remove octocov integration for HTTP benchmarks - Implement direct GitHub Actions commenting - Consolidate output formatting with structured data - Add Markdown file generation for PR comments 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: use origin/main as default baseline and add git fetch - Change default baseline from 'main' to 'origin/main' for CI compatibility - Add git fetch to ensure remote refs are available - Fixes GitHub Actions error with git checkout main 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: add /benchmark command workflow - Create separate command.yml for PR comment triggers - Remove automatic benchmark execution from ci.yml - Add /benchmark command to trigger HTTP benchmarks on demand - Update README with command usage instructions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * feat: add permission check for benchmark command - Restrict /benchmark command to users with admin, maintain, or write permissions - Add user permission validation before running benchmark - Fail gracefully with clear error message for unauthorized users 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * refactor: revert to automatic benchmark execution on PR - Remove command.yml workflow (no longer needed) - Add HTTP benchmark job back to ci.yml for automatic execution - Reduce default duration from 10s to 5s for faster CI - Update README to reflect automatic execution 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * perf: eliminate build step for faster benchmark execution - Use TypeScript source files directly instead of compiled dist - Remove build requirements from benchmark process - Change log message from "Building" to "Preparing" - Remove package.json copy (not needed for simple imports) - Maintain 10s duration for both local and CI execution This significantly reduces benchmark execution time by skipping the TypeScript compilation step entirely. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: use github.graphql instead of github.rest.graphql - Correct GraphQL API usage for minimizing comments - Fix TypeError in GitHub Actions script 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> ---------

authored by Yusuke Wada · committed by GitHub · parent c43c53f · Browse files · 9 files+403 added−468 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Claude <noreply@anthropic.com>

Diff stats

9 files+403 added−468 removed

  • other:+403 added−468 removed

9 files+403 added−468 removed

modified:.github/actions/perf-measures/action.yml-14 removed
modified:.github/workflows/ci.yml+55 added-2 removed
181 unmodified lines
182 name: coverage-lambda-edge183 path: coverage/184185 perf-measures-check-on-pr:186 name: 'Type & Bundle size & Speed Check on PR'186 name: 'Type & Bundle size Check on PR'187 runs-on: ubuntu-latest188 if: github.event_name == 'pull_request'189 steps:190 - uses: actions/checkout@v4191 - uses: ./.github/actions/perf-measures192 with:193 target-ref: 'auto'194195 http-benchmark-on-pr:196 name: 'HTTP Speed Check on PR'197 runs-on: ubuntu-latest198 if: github.event_name == 'pull_request'199 steps:200 - uses: actions/checkout@v4201 - uses: oven-sh/setup-bun@v2202 - run: bun install203 - name: Install bombardier204 run: |205 wget -O bombardier https://github.com/codesenberg/bombardier/releases/download/v2.0.1/bombardier-linux-amd64206 chmod +x bombardier207 sudo mv bombardier /usr/local/bin/208 - name: Run HTTP benchmark209 run: |210 cd benchmarks/http-server211 bun run benchmark.ts212 - name: Comment PR213 uses: actions/github-script@v7214 with:215 script: |216 const fs = require('fs');217 const results = fs.readFileSync('benchmarks/http-server/benchmark-results.md', 'utf8');218219 // Minimize previous benchmark comments220 const comments = await github.rest.issues.listComments({221 owner: context.repo.owner,222 repo: context.repo.repo,223 issue_number: context.issue.number224 });225226 for (const comment of comments.data) {227 if (comment.body.includes('## HTTP Performance Benchmark')) {228 await github.graphql(`229 mutation {230 minimizeComment(input: { subjectId: "${comment.node_id}", classifier: OUTDATED }) {231 minimizedComment {232 isMinimized233 }234 }235 }236 `);237 }238 }239240 // Post new comment241 github.rest.issues.createComment({242 issue_number: context.issue.number,243 owner: context.repo.owner,244 repo: context.repo.repo,245 body: results246 });247248 perf-measures-check-on-main:196 name: 'Type & Bundle size & Speed Check on Main'249 name: 'Type & Bundle size Check on Main'250 runs-on: ubuntu-latest251 if: github.ref == 'refs/heads/main'252 steps:253 - uses: actions/checkout@v4
3 unmodified lines
added:benchmarks/http-server/.gitignore+2 added
1.benchmark-temp/2benchmark-results.md
added:benchmarks/http-server/benchmark.ts+325 added
1/**2 * Hono HTTP Performance Benchmark3 *4 * Inspired by https://github.com/SaltyAom/bun-http-framework-benchmark5 *6 * Usage:7 * bun run benchmark.ts [options]8 *9 * Options:10 * --baseline=<ref> Git reference for baseline (default: main)11 * --target=<ref> Git reference for target (default: current)12 * --runs=<number> Number of benchmark runs (default: 1)13 * --duration=<number> Duration of each test in seconds (default: 10)14 * --skip-tests Skip endpoint validation tests15 */1617import { spawn } from 'node:child_process'18import { existsSync, mkdirSync, writeFileSync, rmSync } from 'node:fs'19import { join } from 'node:path'2021// Configuration from command line arguments22const baseline = process.argv.find((arg) => arg.startsWith('--baseline='))?.split('=')[1] || 'origin/main'23const target = process.argv.find((arg) => arg.startsWith('--target='))?.split('=')[1] || 'current'24const runs = parseInt(process.argv.find((arg) => arg.startsWith('--runs='))?.split('=')[1] || '1')25const duration = parseInt(26 process.argv.find((arg) => arg.startsWith('--duration='))?.split('=')[1] || '10'27)28const concurrency = 50029const skipTests = process.argv.includes('--skip-tests')3031const SCRIPT_DIR = import.meta.dirname32const TEMP_DIR = join(SCRIPT_DIR, '.benchmark-temp')33const HONO_ROOT = join(SCRIPT_DIR, '../..')3435// Test app template (embedded to avoid file dependency issues)36const getAppTemplate = () => `import { Hono } from './src/index.ts'37import { RegExpRouter } from './src/router/reg-exp-router/index.ts'3839const app = new Hono({ router: new RegExpRouter() })4041app42 .get('/', (c) => c.text('Hi'))43 .post('/json', (c) => c.req.json().then(c.json))44 .get('/id/:id', (c) => {45 const id = c.req.param('id')46 const name = c.req.query('name')47 c.header('x-powered-by', 'benchmark')48 return c.text(\`\${id} \${name}\`)49 })5051export default app`5253const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))5455const runCommand = async (command: string, cwd: string) => {56 const parts = command.split(' ')57 const proc = spawn(parts[0], parts.slice(1), { cwd })5859 let stdout = ''60 let stderr = ''6162 proc.stdout.on('data', (data) => {63 stdout += data64 })65 proc.stderr.on('data', (data) => {66 stderr += data67 })6869 const exitCode = await new Promise<number>((resolve) => {70 proc.on('close', resolve)71 })7273 if (exitCode !== 0) {74 console.error(`Command failed: ${command}`)75 console.error(`Exit code: ${exitCode}`)76 console.error(`Stdout: ${stdout}`)77 console.error(`Stderr: ${stderr}`)78 throw new Error(`Command failed: ${command}`)79 }8081 return { stdout, stderr }82}8384const setupTemp = () => {85 if (existsSync(TEMP_DIR)) {86 rmSync(TEMP_DIR, { recursive: true })87 }88 mkdirSync(TEMP_DIR, { recursive: true })89 writeFileSync(join(TEMP_DIR, 'body.json'), '{"hello":"world"}')90}9192const buildVersion = async (version: string, name: string) => {93 console.log(`📦 Preparing ${name} (${version})...`)9495 let needsRestore = false96 let stashRef = ''9798 if (version === 'current') {99 // No build needed - use src directly100 } else {101 // Ensure we have the latest remote refs102 await runCommand('git fetch origin', HONO_ROOT)103 104 try {105 const stashResult = await runCommand('git stash push -m "benchmark-temp"', HONO_ROOT)106 needsRestore = stashResult.stdout.includes('Saved working directory')107 if (needsRestore) {108 stashRef = 'stash@{0}'109 }110 } catch {111 // No changes to stash112 }113114 await runCommand(`git checkout ${version}`, HONO_ROOT)115 await runCommand('bun install', HONO_ROOT)116 // No build needed - use src directly117 }118119 const versionDir = join(TEMP_DIR, name)120 mkdirSync(versionDir, { recursive: true })121 await runCommand(`cp -r ${HONO_ROOT}/src ${versionDir}/src`, process.cwd())122123 const appPath = join(versionDir, 'app.ts')124 writeFileSync(appPath, getAppTemplate())125126 // Test endpoints (optional)127 if (!skipTests) {128 console.log(`🧪 Testing endpoints for ${name}...`)129 const server = spawn('bun', [appPath], {130 cwd: TEMP_DIR,131 env: { ...process.env, NODE_ENV: 'production' },132 })133 await sleep(2000)134135 try {136 const res1 = await fetch('http://127.0.0.1:3000/')137 if ((await res1.text()) !== 'Hi') {138 throw new Error('[GET /] test failed')139 }140141 const res2 = await fetch('http://127.0.0.1:3000/id/1?name=bun')142 if (res2.headers.get('x-powered-by') !== 'benchmark' || (await res2.text()) !== '1 bun') {143 throw new Error('[GET /id/:id] test failed')144 }145146 const body = JSON.stringify({ hello: 'world' })147 const res3 = await fetch('http://127.0.0.1:3000/json', {148 method: 'POST',149 body,150 headers: { 'content-type': 'application/json', 'content-length': body.length.toString() },151 })152 if (153 !res3.headers.get('content-type')?.includes('application/json') ||154 (await res3.text()) !== body155 ) {156 throw new Error('[POST /json] test failed')157 }158159 console.log(` ✅ Tests passed for ${name}`)160 } finally {161 server.kill()162 await sleep(1000)163 }164 } else {165 console.log(` ⏭️ Skipping endpoint tests for ${name}`)166 }167168 // Restore git state169 if (version !== 'current' && needsRestore) {170 await runCommand('git checkout -', HONO_ROOT)171 await runCommand(`git stash pop ${stashRef}`, HONO_ROOT)172 } else if (version !== 'current') {173 await runCommand('git checkout -', HONO_ROOT)174 }175176 return appPath177}178179const runBenchmark = async (appPath: string, name: string) => {180 console.log(`⚡ Running HTTP benchmark for ${name}...`)181182 const bodyFile = join(TEMP_DIR, 'body.json')183 const commands = [184 `bombardier --fasthttp -c ${concurrency} -d ${duration}s http://127.0.0.1:3000/`,185 `bombardier --fasthttp -c ${concurrency} -d ${duration}s http://127.0.0.1:3000/id/1?name=bun`,186 `bombardier --fasthttp -c ${concurrency} -d ${duration}s -m POST -H Content-Type:application/json -f ${bodyFile} http://127.0.0.1:3000/json`,187 ]188189 const allRuns: number[][] = []190191 for (let run = 0; run < runs; run++) {192 console.log(` Run ${run + 1}/${runs}`)193194 const server = spawn('bun', [appPath], {195 cwd: TEMP_DIR,196 env: { ...process.env, NODE_ENV: 'production' },197 })198 await sleep(1000)199200 const runResults: number[] = []201202 try {203 for (const command of commands) {204 const result = await runCommand(command, process.cwd())205 console.log(result.stdout)206207 const match = result.stdout.match(/Reqs\/sec\s+(\d+[.|,]\d+)/)208 if (match) {209 runResults.push(parseFloat(match[1].replace(',', '')))210 } else {211 console.log('❌ Failed to parse result')212 runResults.push(0)213 }214 }215 } finally {216 server.kill()217 await sleep(500)218 }219220 allRuns.push(runResults)221 }222223 const average = (arr: number[]) => arr.reduce((a, b) => a + b, 0) / arr.length224225 const ping = average(allRuns.map((run) => run[0]))226 const query = average(allRuns.map((run) => run[1]))227 const body = average(allRuns.map((run) => run[2]))228 const overall = (ping + query + body) / 3229230 return { name, average: overall, ping, query, body, runs: allRuns.map((run) => average(run)) }231}232233const main = async () => {234 console.log('🏁 Hono HTTP Benchmark')235 console.log('======================')236 console.log(`Baseline: ${baseline}`)237 console.log(`Target: ${target}`)238 console.log(`Runs: ${runs}`)239 console.log(`Duration: ${duration}s`)240 console.log(`Concurrency: ${concurrency}`)241 console.log(`Skip Tests: ${skipTests}`)242 console.log('')243244 setupTemp()245246 try {247 // Compare baseline vs target248 const baselinePath = await buildVersion(baseline, 'baseline')249 const targetPath = await buildVersion(target, 'target')250251 const baselineResult = await runBenchmark(baselinePath, 'baseline')252 const targetResult = await runBenchmark(targetPath, 'target')253254 // Calculate changes255 const calculateChange = (target: number, baseline: number) =>256 (((target - baseline) / baseline) * 100).toFixed(2)257258 const changes = {259 average: calculateChange(targetResult.average, baselineResult.average),260 ping: calculateChange(targetResult.ping, baselineResult.ping),261 query: calculateChange(targetResult.query, baselineResult.query),262 body: calculateChange(targetResult.body, baselineResult.body),263 }264265 // Format numbers266 const format = (num: number) => num.toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ',')267 const formatChange = (change: string) => (Number(change) >= 0 ? '+' : '') + change + '%'268269 // Generate table data270 const rows = [271 {272 framework: `hono (${baseline})`,273 runtime: 'bun',274 average: format(baselineResult.average),275 ping: format(baselineResult.ping),276 query: format(baselineResult.query),277 body: format(baselineResult.body),278 },279 {280 framework: `hono (${target})`,281 runtime: 'bun',282 average: format(targetResult.average),283 ping: format(targetResult.ping),284 query: format(targetResult.query),285 body: format(targetResult.body),286 },287 {288 framework: 'Change',289 runtime: '',290 average: formatChange(changes.average),291 ping: formatChange(changes.ping),292 query: formatChange(changes.query),293 body: formatChange(changes.body),294 },295 ]296297 const table = [298 '| Framework | Runtime | Average | Ping | Query | Body |',299 '| --- | --- | --- | --- | --- | --- |',300 ...rows.map(301 (row) =>302 `| ${row.framework} | ${row.runtime} | ${row.average} | ${row.ping} | ${row.query} | ${row.body} |`303 ),304 ]305306 // Console output307 console.log('')308 table.forEach((line) => console.log(line))309 console.log('')310311 // Markdown output312 const markdownOutput = ['## HTTP Performance Benchmark', '', ...table].join('\n')313314 writeFileSync(join(SCRIPT_DIR, 'benchmark-results.md'), markdownOutput)315 } catch (error) {316 console.error('❌ Benchmark failed:', error)317 throw error318 } finally {319 if (existsSync(TEMP_DIR)) {320 rmSync(TEMP_DIR, { recursive: true })321 }322 }323}324325main()
added:benchmarks/http-server/README.md+21 added
deleted:perf-measures/speed-check/scripts/benchmark.ts-390 removed
1/**2 * Hono HTTP Performance Benchmark3 *4 * Inspired by https://github.com/SaltyAom/bun-http-framework-benchmark5 *6 * Usage:7 * bun run benchmark.ts [options]8 *9 * Options:10 * --baseline=<ref> Git reference for baseline (default: main)11 * --target=<ref> Git reference for target (default: current)12 * --runs=<number> Number of benchmark runs (default: 1)13 * --duration=<number> Duration of each test in seconds (default: 10)14 * --skip-tests Skip endpoint validation tests15 */1617import { spawn } from 'node:child_process'18import { existsSync, mkdirSync, writeFileSync, rmSync } from 'node:fs'19import { join } from 'node:path'2021// Configuration from command line arguments22const ciMode = process.argv.includes('--ci')23const baseline = process.argv.find((arg) => arg.startsWith('--baseline='))?.split('=')[1] || 'main'24const target = process.argv.find((arg) => arg.startsWith('--target='))?.split('=')[1] || 'current'25const runs = parseInt(process.argv.find((arg) => arg.startsWith('--runs='))?.split('=')[1] || '1')26const duration = parseInt(27 process.argv.find((arg) => arg.startsWith('--duration='))?.split('=')[1] || '10'28)29const concurrency = 50030const skipTests = process.argv.includes('--skip-tests')3132const SCRIPT_DIR = join(import.meta.dirname, '..')33const TEMP_DIR = join(SCRIPT_DIR, '.benchmark-temp')34const HONO_ROOT = join(SCRIPT_DIR, '../..')3536// Test app template (embedded to avoid file dependency issues)37const getAppTemplate = () => `import { Hono } from './dist/index.js'38import { RegExpRouter } from './dist/router/reg-exp-router/index.js'3940const app = new Hono({ router: new RegExpRouter() })4142app43 .get('/', (c) => c.text('Hi'))44 .post('/json', (c) => c.req.json().then(c.json))45 .get('/id/:id', (c) => {46 const id = c.req.param('id')47 const name = c.req.query('name')48 c.header('x-powered-by', 'benchmark')49 return c.text(\`\${id} \${name}\`)50 })5152export default app`5354const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))5556const log = (...args: unknown[]) => {57 if (!ciMode) {58 console.log(...args)59 }60}6162const runCommand = async (command: string, cwd: string) => {63 const parts = command.split(' ')64 const proc = spawn(parts[0], parts.slice(1), { cwd })6566 let stdout = ''67 let stderr = ''6869 proc.stdout.on('data', (data) => {70 stdout += data71 })72 proc.stderr.on('data', (data) => {73 stderr += data74 })7576 const exitCode = await new Promise<number>((resolve) => {77 proc.on('close', resolve)78 })7980 if (exitCode !== 0) {81 console.error(`Command failed: ${command}`)82 console.error(`Exit code: ${exitCode}`)83 console.error(`Stdout: ${stdout}`)84 console.error(`Stderr: ${stderr}`)85 throw new Error(`Command failed: ${command}`)86 }8788 return { stdout, stderr }89}9091const setupTemp = () => {92 if (existsSync(TEMP_DIR)) {93 rmSync(TEMP_DIR, { recursive: true })94 }95 mkdirSync(TEMP_DIR, { recursive: true })96 writeFileSync(join(TEMP_DIR, 'body.json'), '{"hello":"world"}')97}9899const buildVersion = async (version: string, name: string) => {100 log(`📦 Building ${name} (${version})...`)101102 let needsRestore = false103 let stashRef = ''104105 if (version === 'current') {106 if (!ciMode) {107 await runCommand('bun run build', HONO_ROOT)108 }109 } else {110 try {111 const stashResult = await runCommand('git stash push -m "benchmark-temp"', HONO_ROOT)112 needsRestore = stashResult.stdout.includes('Saved working directory')113 if (needsRestore) {114 stashRef = 'stash@{0}'115 }116 } catch {117 // No changes to stash118 }119120 await runCommand(`git checkout ${version}`, HONO_ROOT)121 await runCommand('bun install', HONO_ROOT)122 if (!ciMode) {123 await runCommand('bun run build', HONO_ROOT)124 }125 }126127 const versionDir = join(TEMP_DIR, name)128 mkdirSync(versionDir, { recursive: true })129 await runCommand(`cp -r ${HONO_ROOT}/dist ${versionDir}/dist`, process.cwd())130131 const appPath = join(versionDir, 'app.js')132 writeFileSync(appPath, getAppTemplate())133134 // Test endpoints (optional)135 if (!skipTests) {136 log(`🧪 Testing endpoints for ${name}...`)137 const server = spawn('bun', [appPath], {138 cwd: TEMP_DIR,139 env: { ...process.env, NODE_ENV: 'production' },140 })141 await sleep(2000)142143 try {144 const res1 = await fetch('http://127.0.0.1:3000/')145 if ((await res1.text()) !== 'Hi') {146 throw new Error('[GET /] test failed')147 }148149 const res2 = await fetch('http://127.0.0.1:3000/id/1?name=bun')150 if (res2.headers.get('x-powered-by') !== 'benchmark' || (await res2.text()) !== '1 bun') {151 throw new Error('[GET /id/:id] test failed')152 }153154 const body = JSON.stringify({ hello: 'world' })155 const res3 = await fetch('http://127.0.0.1:3000/json', {156 method: 'POST',157 body,158 headers: { 'content-type': 'application/json', 'content-length': body.length.toString() },159 })160 if (161 !res3.headers.get('content-type')?.includes('application/json') ||162 (await res3.text()) !== body163 ) {164 throw new Error('[POST /json] test failed')165 }166167 log(` ✅ Tests passed for ${name}`)168 } finally {169 server.kill()170 await sleep(1000)171 }172 } else {173 log(` ⏭️ Skipping endpoint tests for ${name}`)174 }175176 // Restore git state177 if (version !== 'current' && needsRestore) {178 await runCommand('git checkout -', HONO_ROOT)179 await runCommand(`git stash pop ${stashRef}`, HONO_ROOT)180 } else if (version !== 'current') {181 await runCommand('git checkout -', HONO_ROOT)182 }183184 return appPath185}186187const runBenchmark = async (appPath: string, name: string) => {188 log(`⚡ Running HTTP benchmark for ${name}...`)189190 const bodyFile = join(TEMP_DIR, 'body.json')191 const commands = [192 `bombardier --fasthttp -c ${concurrency} -d ${duration}s http://127.0.0.1:3000/`,193 `bombardier --fasthttp -c ${concurrency} -d ${duration}s http://127.0.0.1:3000/id/1?name=bun`,194 `bombardier --fasthttp -c ${concurrency} -d ${duration}s -m POST -H Content-Type:application/json -f ${bodyFile} http://127.0.0.1:3000/json`,195 ]196197 const allRuns: number[][] = []198199 for (let run = 0; run < runs; run++) {200 log(` Run ${run + 1}/${runs}`)201202 const server = spawn('bun', [appPath], {203 cwd: TEMP_DIR,204 env: { ...process.env, NODE_ENV: 'production' },205 })206 await sleep(1000)207208 const runResults: number[] = []209210 try {211 for (const command of commands) {212 const result = await runCommand(command, process.cwd())213 log(result.stdout)214215 const match = result.stdout.match(/Reqs\/sec\s+(\d+[.|,]\d+)/)216 if (match) {217 runResults.push(parseFloat(match[1].replace(',', '')))218 } else {219 log('❌ Failed to parse result')220 runResults.push(0)221 }222 }223 } finally {224 server.kill()225 await sleep(500)226 }227228 allRuns.push(runResults)229 }230231 const average = (arr: number[]) => arr.reduce((a, b) => a + b, 0) / arr.length232233 const ping = average(allRuns.map((run) => run[0]))234 const query = average(allRuns.map((run) => run[1]))235 const body = average(allRuns.map((run) => run[2]))236 const overall = (ping + query + body) / 3237238 return { name, average: overall, ping, query, body, runs: allRuns.map((run) => average(run)) }239}240241const main = async () => {242 log('🏁 Hono HTTP Benchmark')243 log('======================')244 log(`Baseline: ${baseline}`)245 log(`Target: ${target}`)246 log(`Runs: ${runs}`)247 log(`Duration: ${duration}s`)248 log(`Concurrency: ${concurrency}`)249 log(`Skip Tests: ${skipTests}`)250 log('')251252 setupTemp()253254 try {255 if (ciMode) {256 // CI mode: measure current branch only (dist already built)257 const versionDir = join(TEMP_DIR, 'current')258 mkdirSync(versionDir, { recursive: true })259 const distPath = join(HONO_ROOT, 'dist')260 await runCommand(`cp -r ${distPath} ${versionDir}/`, process.cwd())261262 const appPath = join(versionDir, 'app.js')263 writeFileSync(appPath, getAppTemplate())264265 const targetResult = await runBenchmark(appPath, 'current')266267 // Generate octocov-compatible output268 const benchmark = {269 key: 'speed-check',270 name: 'HTTP speed check',271 metrics: [272 {273 key: 'ping',274 name: 'Ping (req/s)',275 value: targetResult.ping,276 unit: 'req/s',277 },278 {279 key: 'query',280 name: 'Query (req/s)',281 value: targetResult.query,282 unit: 'req/s',283 },284 {285 key: 'body',286 name: 'Body (req/s)',287 value: targetResult.body,288 unit: 'req/s',289 },290 {291 key: 'average',292 name: 'Average (req/s)',293 value: targetResult.average,294 unit: 'req/s',295 },296 ],297 }298299 console.log(JSON.stringify(benchmark, null, 2))300 return301 }302303 // Normal mode: compare baseline vs target304 const baselinePath = await buildVersion(baseline, 'baseline')305 const targetPath = await buildVersion(target, 'target')306307 const baselineResult = await runBenchmark(baselinePath, 'baseline')308 const targetResult = await runBenchmark(targetPath, 'target')309310 // Calculate changes311 const overallChange = (312 ((targetResult.average - baselineResult.average) / baselineResult.average) *313 100314 ).toFixed(2)315 const pingChange = (316 ((targetResult.ping - baselineResult.ping) / baselineResult.ping) *317 100318 ).toFixed(2)319 const queryChange = (320 ((targetResult.query - baselineResult.query) / baselineResult.query) *321 100322 ).toFixed(2)323 const bodyChange = (324 ((targetResult.body - baselineResult.body) / baselineResult.body) *325 100326 ).toFixed(2)327328 // Format output329 const baselineName = `hono (${baseline})`330 const targetName = `hono (${target})`331 const maxNameLength = Math.max(baselineName.length, targetName.length, 16)332333 const formatName = (name: string) => name.padEnd(maxNameLength)334 const formatNumber = (num: number) => num.toFixed(2).padStart(10)335 const formatAverage = (num: number) => num.toFixed(3).padStart(7)336 const formatChange = (change: string) =>337 ((Number(change) >= 0 ? '+' : '') + change + '%').padStart(10)338339 console.log('')340 console.log(341 `| ${'Framework'.padEnd(342 maxNameLength343 )} | Runtime | Average | Ping | Query | Body |`344 )345 console.log(346 `| ${'-'.repeat(maxNameLength)} | ------- | ------- | ---------- | ---------- | ---------- |`347 )348 console.log(349 `| ${formatName(baselineName)} | bun | ${formatAverage(350 baselineResult.average351 )} | ${formatNumber(baselineResult.ping)} | ${formatNumber(352 baselineResult.query353 )} | ${formatNumber(baselineResult.body)} |`354 )355 console.log(356 `| ${formatName(targetName)} | bun | ${formatAverage(357 targetResult.average358 )} | ${formatNumber(targetResult.ping)} | ${formatNumber(359 targetResult.query360 )} | ${formatNumber(targetResult.body)} |`361 )362 console.log(363 `| ${' '.repeat(maxNameLength)} | | ${(364 (Number(overallChange) >= 0 ? '+' : '') +365 overallChange +366 '%'367 ).padStart(7)} | ${formatChange(pingChange)} | ${formatChange(queryChange)} | ${formatChange(368 bodyChange369 )} |`370 )371 console.log('')372373 // Individual changes summary374 console.log('📊 Performance Changes:')375 console.log(` Overall: ${Number(overallChange) >= 0 ? '+' : ''}${overallChange}%`)376 console.log(` Ping: ${Number(pingChange) >= 0 ? '+' : ''}${pingChange}%`)377 console.log(` Query: ${Number(queryChange) >= 0 ? '+' : ''}${queryChange}%`)378 console.log(` Body: ${Number(bodyChange) >= 0 ? '+' : ''}${bodyChange}%`)379 console.log('')380 } catch (error) {381 console.error('❌ Benchmark failed:', error)382 throw error383 } finally {384 if (existsSync(TEMP_DIR)) {385 rmSync(TEMP_DIR, { recursive: true })386 }387 }388}389390main()
deleted:perf-measures/speed-check/.gitignore-2 removed
1benchmark-results.json2.benchmark-temp
deleted:perf-measures/speed-check/README.md-58 removed
modified:perf-measures/.octocov.consolidated.perf-measures.yml-2 removed