Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | #!/usr/bin/env bun |
| 2 | |
| 3 | /** |
| 4 | * Generate a Markdown table comparing API metrics before and after an optimization PR. |
| 5 | * |
| 6 | * Usage: |
| 7 | * pnpm run metrics |
| 8 | */ |
| 9 | |
| 10 | interface Metric { |
| 11 | requests: number; |
| 12 | megabytes: number; |
| 13 | } |
| 14 | |
| 15 | interface MetricRow { |
| 16 | name: string; |
| 17 | before: Metric; |
| 18 | after: Metric; |
| 19 | } |
| 20 | |
| 21 | const data: MetricRow[] = [ |
| 22 | { |
| 23 | name: 'Default', |
| 24 | before: { requests: 4, megabytes: 1.71 }, |
| 25 | after: { requests: 3, megabytes: 1.7 }, |
| 26 | }, |
| 27 | { |
| 28 | name: '`--type-tools`', |
| 29 | before: { requests: 26, megabytes: 111.3 }, |
| 30 | after: { requests: 24, megabytes: 110.62 }, |
| 31 | }, |
| 32 | { |
| 33 | name: '`--toolkits entelligence`', |
| 34 | before: { requests: 5, megabytes: 2.35 }, |
| 35 | after: { requests: 3, megabytes: 76.21 / 1024 }, // Convert KB to MB |
| 36 | }, |
| 37 | { |
| 38 | name: '`--type-tools` + `--toolkits entelligence`', |
| 39 | before: { requests: 27, megabytes: 111.94 }, |
| 40 | after: { requests: 3, megabytes: 6.21 / 1024 }, // Convert KB to MB |
| 41 | }, |
| 42 | ]; |
| 43 | |
| 44 | function percentChange(before: number, after: number): string { |
| 45 | let change = ((after - before) / before) * 100; |
| 46 | // Cap at -99.9% unless it's truly 0 |
| 47 | if (after > 0 && change < -99.9) { |
| 48 | change = -99.9; |
| 49 | } |
| 50 | const sign = change > 0 ? '+' : ''; |
| 51 | return `${sign}${change.toFixed(1)}%`; |
| 52 | } |
| 53 | |
| 54 | function formatMB(mb: number): string { |
| 55 | if (mb < 1) { |
| 56 | return `${(mb * 1024).toFixed(2)} KB`; |
| 57 | } |
| 58 | return `${mb.toFixed(2)} MB`; |
| 59 | } |
| 60 | |
| 61 | function generateMarkdownTable(rows: MetricRow[]): string { |
| 62 | const lines: string[] = []; |
| 63 | |
| 64 | lines.push('# Metrics Comparison: Before vs After Optimization'); |
| 65 | lines.push(''); |
| 66 | lines.push( |
| 67 | '| Case | Requests (Before) | Requests (After) | Requests Δ | Downloaded (Before) | Downloaded (After) | Downloaded Δ |' |
| 68 | ); |
| 69 | lines.push( |
| 70 | '|------|-------------------|------------------|------------|---------------------|--------------------|--------------| ' |
| 71 | ); |
| 72 | |
| 73 | for (const row of rows) { |
| 74 | const reqChange = percentChange(row.before.requests, row.after.requests); |
| 75 | const mbChange = percentChange(row.before.megabytes, row.after.megabytes); |
| 76 | |
| 77 | lines.push( |
| 78 | `| ${row.name} | ${row.before.requests} | ${row.after.requests} | ${reqChange} | ${formatMB(row.before.megabytes)} | ${formatMB(row.after.megabytes)} | ${mbChange} |` |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | return lines.join('\n'); |
| 83 | } |
| 84 | |
| 85 | const table = generateMarkdownTable(data); |
| 86 | console.log(table); |