11#!/usr/bin/env tsx
22
3- import chalk from "chalk" ;
43import { mkdtempSync , rmSync } from "node:fs" ;
54import { tmpdir } from "node:os" ;
65import { join } from "node:path" ;
98 parseCacheProfile ,
109 type CacheProfile ,
1110} from "./cache-profile.js" ;
11+ import { colors } from "./colors.js" ;
1212import {
1313 createDriver ,
1414 getAvailableDrivers ,
@@ -109,7 +109,7 @@ for (let i = 0; i < args.length; i++) {
109109 } else if ( args [ i ] === "--iterations" && i + 1 < args . length ) {
110110 const iterations = Number ( args [ i + 1 ] ) ;
111111 if ( ! Number . isInteger ( iterations ) || iterations < 1 ) {
112- console . error ( chalk . red ( "--iterations must be a positive integer" ) ) ;
112+ console . error ( colors . red ( "--iterations must be a positive integer" ) ) ;
113113 process . exit ( 1 ) ;
114114 }
115115 options . iterations = iterations ;
@@ -122,7 +122,7 @@ for (let i = 0; i < args.length; i++) {
122122 }
123123 options . cacheProfile = parseCacheProfile ( profile ) ;
124124 } catch ( error ) {
125- console . error ( chalk . red ( ( error as Error ) . message ) ) ;
125+ console . error ( colors . red ( ( error as Error ) . message ) ) ;
126126 process . exit ( 1 ) ;
127127 }
128128 i ++ ;
@@ -163,7 +163,7 @@ const driversToTest = options.drivers ?? getAvailableDrivers();
163163const scenarios = getScenarios ( options . filter ) ;
164164
165165if ( scenarios . length === 0 ) {
166- console . error ( chalk . red ( `No scenarios found matching: ${ options . filter } ` ) ) ;
166+ console . error ( colors . red ( `No scenarios found matching: ${ options . filter } ` ) ) ;
167167 process . exit ( 1 ) ;
168168}
169169
@@ -268,9 +268,9 @@ async function inspectBenchmarkSettings(
268268
269269// Main benchmark function wrapped in async IIFE for CJS compatibility
270270( async ( ) => {
271- console . log ( chalk . bold . cyan ( "🚀 SQLite Driver Performance Benchmark\n" ) ) ;
272- console . log ( chalk . gray ( `Testing drivers: ${ driversToTest . join ( ", " ) } ` ) ) ;
273- console . log ( chalk . gray ( `Scenarios: ${ scenarios . length } \n` ) ) ;
271+ console . log ( colors . bold . cyan ( "🚀 SQLite Driver Performance Benchmark\n" ) ) ;
272+ console . log ( colors . gray ( `Testing drivers: ${ driversToTest . join ( ", " ) } ` ) ) ;
273+ console . log ( colors . gray ( `Scenarios: ${ scenarios . length } \n` ) ) ;
274274
275275 // Drivers actually available this run, in the order requested.
276276 const driverList = driversToTest . filter ( ( d ) =>
@@ -280,13 +280,13 @@ async function inspectBenchmarkSettings(
280280 throw new Error ( "No requested benchmark drivers are available" ) ;
281281 }
282282
283- console . log ( chalk . gray ( `Cache profile: ${ options . cacheProfile } ` ) ) ;
283+ console . log ( colors . gray ( `Cache profile: ${ options . cacheProfile } ` ) ) ;
284284 const benchmarkSettings : Record < string , BenchmarkSettings > = { } ;
285285 for ( const driverName of driverList ) {
286286 const settings = await inspectBenchmarkSettings ( driverName ) ;
287287 benchmarkSettings [ driverName ] = settings ;
288288 console . log (
289- chalk . gray (
289+ colors . gray (
290290 ` ${ driverName } : cache_size=${ settings . effectiveCacheSize } ` +
291291 `(packaged=${ settings . initialCacheSize } ), ` +
292292 `journal_mode=${ settings . journalMode } , ` +
@@ -315,17 +315,17 @@ async function inspectBenchmarkSettings(
315315 const isWarmup = pass === 0 ;
316316
317317 if ( isWarmup ) {
318- console . log ( chalk . gray ( "Warmup pass...\n" ) ) ;
318+ console . log ( colors . gray ( "Warmup pass...\n" ) ) ;
319319 } else {
320- console . log ( chalk . bold . cyan ( "\nMeasured pass:\n" ) ) ;
320+ console . log ( colors . bold . cyan ( "\nMeasured pass:\n" ) ) ;
321321 }
322322
323323 for ( const [ scenarioKey , scenario ] of scenarios ) {
324324 if ( isWarmup ) {
325- process . stdout . write ( chalk . gray ( `\n ${ scenario . name } :` ) ) ;
325+ process . stdout . write ( colors . gray ( `\n ${ scenario . name } :` ) ) ;
326326 } else {
327- console . log ( chalk . bold . yellow ( `\n📊 ${ scenario . name } ` ) ) ;
328- console . log ( chalk . gray ( ` ${ scenario . description } ` ) ) ;
327+ console . log ( colors . bold . yellow ( `\n📊 ${ scenario . name } ` ) ) ;
328+ console . log ( colors . gray ( ` ${ scenario . description } ` ) ) ;
329329 }
330330
331331 if ( ! isWarmup ) {
@@ -382,8 +382,8 @@ async function inspectBenchmarkSettings(
382382 } catch ( err ) {
383383 failed . add ( driverName ) ;
384384 const msg = `✗ Error in ${ driverName } : ${ ( err as Error ) . message } ` ;
385- if ( isWarmup ) process . stdout . write ( chalk . yellow ( ` [${ msg } ]` ) ) ;
386- else console . error ( chalk . red ( ` ${ msg } ` ) ) ;
385+ if ( isWarmup ) process . stdout . write ( colors . yellow ( ` [${ msg } ]` ) ) ;
386+ else console . error ( colors . red ( ` ${ msg } ` ) ) ;
387387 }
388388 }
389389 }
@@ -396,13 +396,13 @@ async function inspectBenchmarkSettings(
396396
397397 if ( isWarmup ) {
398398 process . stdout . write (
399- chalk . gray (
399+ colors . gray (
400400 ` ${ driverName } :${ Math . round ( opsPerSec ) . toLocaleString ( ) } ` ,
401401 ) ,
402402 ) ;
403403 } else {
404404 console . log (
405- chalk . green (
405+ colors . green (
406406 ` ${ driverName } : ${ Math . round ( opsPerSec ) . toLocaleString ( ) } ops/sec ±${ rme . toFixed ( 1 ) } % (${ s . length } trials × ${ iters [ driverName ] . toLocaleString ( ) } iters)` ,
407407 ) ,
408408 ) ;
@@ -425,7 +425,7 @@ async function inspectBenchmarkSettings(
425425 }
426426
427427 // Summary
428- console . log ( chalk . bold . cyan ( "\n\n### 📈 Summary\n" ) ) ;
428+ console . log ( colors . bold . cyan ( "\n\n### 📈 Summary\n" ) ) ;
429429
430430 // Keep the configuration directly beside the copyable Markdown table. The
431431 // startup preamble is useful interactively, but is easy to omit when results
@@ -521,15 +521,15 @@ async function inspectBenchmarkSettings(
521521 "‡ batched write — one durable commit amortized over ~1000 rows, so " +
522522 "driver differences remain visible (don't read these as ties)." ,
523523 ) ;
524- console . log ( "\n" + chalk . gray ( notes . join ( "\n" ) ) ) ;
524+ console . log ( "\n" + colors . gray ( notes . join ( "\n" ) ) ) ;
525525 }
526526
527527 // Memory usage report
528528 if ( options . memory && global . gc ) {
529529 global . gc ( ) ;
530530 const memoryFinal = process . memoryUsage ( ) ;
531531
532- console . log ( chalk . bold . cyan ( "\n\n### 💾 Memory Usage\n" ) ) ;
532+ console . log ( colors . bold . cyan ( "\n\n### 💾 Memory Usage\n" ) ) ;
533533
534534 const formatMB = ( bytes : number ) =>
535535 `${ ( bytes / 1024 / 1024 ) . toFixed ( 1 ) } MB` ;
@@ -548,7 +548,7 @@ async function inspectBenchmarkSettings(
548548
549549 console . log (
550550 "\n" +
551- chalk . gray (
551+ colors . gray (
552552 "📋 Memory table generated above - copy/paste ready for documentation!" ,
553553 ) ,
554554 ) ;
@@ -575,8 +575,8 @@ async function inspectBenchmarkSettings(
575575 } ) ;
576576 writeCharts ( charts , outDir ) ;
577577 console . log (
578- chalk . bold . cyan ( `\n\n### 📊 Charts\n` ) +
579- chalk . gray ( `Wrote ${ charts . size } SVG chart(s) to ${ outDir } ` ) ,
578+ colors . bold . cyan ( `\n\n### 📊 Charts\n` ) +
579+ colors . gray ( `Wrote ${ charts . size } SVG chart(s) to ${ outDir } ` ) ,
580580 ) ;
581581 }
582582
0 commit comments