Skip to content

Commit b468302

Browse files
Copilotmathiasrw
andcommitted
Address code review feedback - improve code readability
Co-authored-by: mathiasrw <[email protected]>
1 parent 4235b97 commit b468302

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ import alasql175 from 'alasql-1.7.5';
8686

8787
## Sample Output
8888

89+
The benchmark produces formatted output showing performance metrics for each version (actual results will vary based on your machine):
90+
8991
```
9092
╔══════════════════════════════════════════════════════════════════════════════╗
9193
║ AlaSQL Historical Performance Benchmark ║

benchmark.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ import alasql300 from 'alasql-3.0.0';
1313
import alasql400 from 'alasql-4.0.0';
1414
import alasql4101 from 'alasql-4.10.1';
1515

16-
// Type definitions
16+
// Configuration constants
17+
const COLUMN_WIDTH = 15;
18+
const MEDALS = ['🥇', '🥈', '🥉'];
19+
20+
function getMedal(rank: number): string {
21+
return rank < MEDALS.length ? MEDALS[rank] : ' ';
22+
}
1723
interface AlaSQLInstance {
1824
(query: string, params?: unknown[]): unknown;
1925
}
@@ -67,13 +73,14 @@ function generateUsers(count: number): Array<{ id: number; name: string; age: nu
6773

6874
function generateOrders(count: number, maxUserId: number): Array<{ id: number; userId: number; product: string; amount: number; date: string }> {
6975
const products = ['Laptop', 'Phone', 'Tablet', 'Monitor', 'Keyboard', 'Mouse', 'Headphones', 'Camera'];
76+
const currentYear = new Date().getFullYear();
7077

7178
return Array.from({ length: count }, (_, i) => ({
7279
id: i + 1,
7380
userId: (i % maxUserId) + 1,
7481
product: products[i % products.length],
7582
amount: 10 + (i * 7) % 990,
76-
date: `2024-${String((i % 12) + 1).padStart(2, '0')}-${String((i % 28) + 1).padStart(2, '0')}`,
83+
date: `${currentYear}-${String((i % 12) + 1).padStart(2, '0')}-${String((i % 28) + 1).padStart(2, '0')}`,
7784
}));
7885
}
7986

@@ -330,7 +337,7 @@ async function main() {
330337
console.log('\n Rank │ Version │ Avg Ops/s');
331338
console.log(' ─────┼───────────┼──────────────');
332339
versionAverages.forEach((v, i) => {
333-
const medal = i === 0 ? '🥇' : i === 1 ? '🥈' : i === 2 ? '🥉' : ' ';
340+
const medal = getMedal(i);
334341
console.log(` ${medal} ${(i + 1).toString().padStart(2)} │ v${v.version.padEnd(8)}${formatOps(v.avgOps).padStart(10)} ops/s`);
335342
});
336343

@@ -341,16 +348,16 @@ async function main() {
341348

342349
// Create a matrix view
343350
const header = ['Test Case', ...versions.map(v => `v${v.version}`)];
344-
console.log(' ' + header.map(h => h.padEnd(15)).join('│ '));
345-
console.log(' ' + header.map(() => '─'.repeat(15)).join('┼─'));
351+
console.log(' ' + header.map(h => h.padEnd(COLUMN_WIDTH)).join('│ '));
352+
console.log(' ' + header.map(() => '─'.repeat(COLUMN_WIDTH)).join('┼─'));
346353

347354
for (const testCase of testCases) {
348-
const row = [testCase.name.substring(0, 14)];
355+
const row = [testCase.name.substring(0, COLUMN_WIDTH - 1)];
349356
for (const v of versions) {
350357
const result = allResults.find(r => r.version === v.version && r.testName === testCase.name);
351358
row.push(result ? `${formatOps(result.opsPerSecond)} ops/s` : 'N/A');
352359
}
353-
console.log(' ' + row.map(c => c.padEnd(15)).join('│ '));
360+
console.log(' ' + row.map(c => c.padEnd(COLUMN_WIDTH)).join('│ '));
354361
}
355362

356363
console.log(`\n${'═'.repeat(80)}`);

0 commit comments

Comments
 (0)