pub fn stats(file: &str, show_tokens: bool) -> Result<(), CliError>Expand description
Generate comprehensive size and efficiency statistics for a HEDL file.
Parses a HEDL file and compares its size and token efficiency against equivalent JSON, YAML, and XML representations. Optionally estimates LLM token counts for context window optimization.
§Arguments
file- Path to the HEDL file to analyzeshow_tokens- Iftrue, includes estimated token counts for LLM context
§Returns
Returns Ok(()) on success.
§Errors
Returns Err if:
- The file cannot be read
- The file contains syntax errors
- Format conversions fail
§Examples
use hedl_cli::commands::stats;
// Show byte size comparison
stats("data.hedl", false)?;
// Show byte and token comparison
stats("data.hedl", true)?;§Output
Displays a formatted table showing:
- File sizes in bytes for HEDL, JSON (compact/pretty), YAML, XML (compact/pretty)
- Size savings (absolute and percentage)
- Estimated token counts (if enabled)
- Token savings compared to other formats
§Performance
Uses parallel processing (rayon) to compute all format conversions simultaneously, achieving 3-5x speedup on multi-core systems. Token estimation is also parallelized.
§Token Estimation
Token counts use a heuristic approximation:
- ~4 characters per content token
- ~3 whitespace characters per token
- Based on empirical averages for structured data formats