word-tally
Output a tally of the number of times unique words appear in source input.
Usage
Usage: word-tally [OPTIONS] [PATH]
Arguments:
[PATH] File path to use as input rather than stdin ("-") [default: -]
Options:
-I, --io <STRATEGY> I/O strategy [default: streamed] [possible values: mmap, streamed, buffered]
-p, --parallel Use threads for parallel processing
-c, --case <FORMAT> Case normalization [default: lower] [possible values: original, upper, lower]
-s, --sort <ORDER> Sort order [default: desc] [possible values: desc, asc, unsorted]
-m, --min-chars <COUNT> Exclude words containing fewer than min chars
-M, --min-count <COUNT> Exclude words appearing fewer than min times
-E, --exclude-words <WORDS> Exclude words from a comma-delimited list
-i, --include <PATTERN> Include only words matching a regex pattern
-x, --exclude <PATTERN> Exclude words matching a regex pattern
-f, --format <FORMAT> Output format [default: text] [possible values: text, json, csv]
-d, --delimiter <VALUE> Delimiter between keys and values [default: " "]
-o, --output <PATH> Write output to file rather than stdout
-v, --verbose Print verbose details
-h, --help Print help (see more with '--help')
-V, --version Print version
Stability Notice
Pre-release level stability: This project is currently in pre-release stage. Expect breaking interface changes at MINOR version bumps (0.x.0) as the API evolves. The library will maintain API stability once it reaches 1.0.0.
Examples
Basic Usage
|
#>> tally 22
#>> word 20
#>> https 11
|
#>> three 3
#>> two 2
#>> one 1
Filtering Words
# Only include words that appear at least 10 times
# Exclude words with fewer than 5 characters
# Exclude words by pattern
# Combining include and exclude patterns
# Exclude specific words
CSV output:
# Using delimiter (manual CSV)
# Using CSV format (with headers)
JSON output:
Transform JSON output for visualization with d3-cloud:
|
Transform and pipe the JSON output to the wordcloud_cli to produce an image:
| |
I/O and Processing Strategies
word-tally supports various I/O modes and parallel processing:
|
Performance Considerations
Synthetic enchmarks with semi-realistic data suggest these strategies based on file size:
| File Size | Best for Speed | Best for Memory | Balanced Approach |
|---|---|---|---|
| Small (<1MB) | Sequential + Memory-mapped | Sequential + Streamed | Sequential + Streamed |
| Medium (1-80MB) | Sequential + Memory-mapped | Sequential + Streamed | Sequential + Memory-mapped |
| Large (>80MB) | Parallel + Memory-mapped | Parallel + Streamed | Parallel + Memory-mapped |
| Very Large (>1GB) | Parallel + Buffered | Parallel + Streamed | Parallel + Streamed |
Anecdotal insights:
- The inflection point where parallel processing becomes faster for me is around 80MB
- At this point, parallel processing may be several times faster than sequential
- For pipes and non-seekable sources, streaming I/O is required
- Memory-mapped I/O provides excellent performance but requires a seekable file
- Sequential streaming processing remains memory-efficient for files under 80MB
Performance can be further tuned through environment variables (detailed below).
Environment Variables
The following environment variables configure various aspects of the library:
Memory allocation and performance in all modes:
WORD_TALLY_UNIQUENESS_RATIO- Divisor for estimating unique words from input size (default: 10)WORD_TALLY_DEFAULT_CAPACITY- Default initial capacity when there is no size hint (default: 1024)WORD_TALLY_WORD_DENSITY- Multiplier for estimating unique words per chunk (default: 15)WORD_TALLY_RESERVE_THRESHOLD- Base threshold for capacity reservation when merging maps (default: 1000, scales with input size)
Parallel processing configuration:
WORD_TALLY_THREADS- Number of threads for parallel processing (default: all available cores)WORD_TALLY_CHUNK_SIZE- Size of chunks for parallel processing in bytes (default: 65536, 64KB)
I/O and processing strategy configuration:
WORD_TALLY_IO- I/O strategy (default: streamed, options: streamed, buffered, memory-mapped)WORD_TALLY_PROCESSING- Processing strategy (default: sequential, options: sequential, parallel)WORD_TALLY_VERBOSE- Enable verbose mode (default: false, options: true/1/yes/on)
Installation
Library Usage
[]
= "0.23.0"
use File;
use ;
The library supports customization including case normalization, sorting, filtering, and I/O and processing strategies.
Documentation
Tests & Benchmarks
Clone the repository.
Run the tests.
Run the benchmarks.
Benchmarks
The project includes comprehensive benchmarks for measuring performance across different strategies:
# Run specific benchmark groups
# Run specific benchmark tests