diff --git a/CLAUDE.md b/CLAUDE.md index 75365a2..0d21d6a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -5,12 +5,15 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ## Commands **Testing:** + - `npm test` - Run all tests (linting, unit tests, coverage, TypeScript definitions) - `npx ava test/.js` - Run a specific test file -- `npx xo` - Run linting only - `npx tsd` - Run TypeScript definition tests only +NO LINTING. DONT ATTEMPT OT LINT + **Benchmarking:** + - `npm run bench` - Run performance benchmarks ## Architecture @@ -18,16 +21,19 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co Chalk is a zero-dependency terminal string styling library built as a pure ESM module. Key architectural elements: 1. **Core Files:** + - `source/index.js` - Main entry point with the chalk factory and chainable API implementation - `source/utilities.js` - Helper functions for string manipulation and color conversion - `source/vendor/` - Vendored dependencies (ansi-styles and supports-color) to avoid external dependencies 2. **Internal Symbols:** + - `GENERATOR` - Manages chalk instance creation and configuration - `STYLER` - Handles style application and chaining - `IS_EMPTY` - Tracks empty string optimization 3. **API Design:** + - Uses ES6 Proxy for dynamic property access (e.g., `chalk.red.bold`) - Chainable API with lazy property definition for performance - Supports nested styles with proper ANSI escape code management @@ -45,4 +51,4 @@ Chalk is a zero-dependency terminal string styling library built as a pure ESM m - All style properties are dynamically generated via Proxy - there's no hardcoded list - Performance is critical - run benchmarks before/after changes to core functionality - The codebase uses symbols for private properties to prevent collisions -- Template literal processing has special handling for newlines and empty strings \ No newline at end of file +- Template literal processing has special handling for newlines and empty strings diff --git a/benchmark.js b/benchmark.js index 7dfdfd0..b5659ca 100644 --- a/benchmark.js +++ b/benchmark.js @@ -1,7 +1,7 @@ import { Bench } from "tinybench"; import chalk from "./source/index.js"; -const bench = new Bench({ time: 150 }); +const bench = new Bench({ time: 1 }); const chalkRed = chalk.red; const chalkBgRed = chalk.bgRed; @@ -50,15 +50,23 @@ bench await bench.run(); -// Custom table output without samples, latency med, or throughput med -const customTable = bench.tasks.map((task) => ({ +// Format throughput values with comma separators +const formatThroughput = (value) => { + return Math.round(value).toLocaleString(); +}; + +// Format time values in nanoseconds (converting from ms) +const formatTime = (milliseconds) => { + const nanoseconds = milliseconds * 1e6; + return Math.round(nanoseconds).toLocaleString() + " ns"; +}; + +// Create custom table with throughput and time columns +const table = bench.tasks.map((task) => ({ "Task name": task.name, - // 'Latency avg (ns)': task.result.latency.mean.toFixed(2) + ' ± ' + task.result.latency.rme.toFixed(2) + '%', - "Throughput avg (ops/s)": - task.result.throughput.mean.toFixed(0) + - " ± " + - task.result.throughput.rme.toFixed(2) + - "%", + "Throughput avg (ops/s)": formatThroughput(task.result.throughput.mean), + "Throughput med (ops/s)": formatThroughput(task.result.throughput.p50), + "Avg time per op": formatTime(task.result.latency.mean), })); -console.table(customTable); +console.table(table); diff --git a/package.json b/package.json index b4e133c..7176496 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ }, "scripts": { "test": "c8 ava && tsd", - "bench": "matcha benchmark.js" + "bench": "node benchmark.js" }, "files": [ "source",