krep is an optimized string search utility designed for maximum throughput and efficiency when processing large files and directories. It is built with performance in mind, offering multiple search algorithms and SIMD acceleration when available.
Note:
Krep is not intended to be a full replacement or direct competitor to feature-rich tools likegreporripgrep. Instead, it aims to be a minimal, efficient, and pragmatic tool focused on speed and simplicity.Krep provides the essential features needed for fast searching, without the extensive options and complexity of more comprehensive search utilities. Its design philosophy is to deliver the fastest possible search for the most common use cases, with a clean and minimal interface.
The name "krep" has an interesting origin. It is inspired by the Icelandic word "kreppan," which means "to grasp quickly" or "to catch firmly." I came across this word while researching efficient techniques for pattern recognition.
Just as skilled fishers identify patterns in the water to locate fish quickly, I designed "krep" to find patterns in text with maximum efficiency. The name is also short and easy to remember—perfect for a command-line utility that users might type hundreds of times per day.
- Multiple search algorithms: Boyer-Moore-Horspool, KMP, Aho-Corasick for optimal performance across different pattern types
- Algorithm selection: Automatic smart selection with optional
--algooverride for fine-tuning - SIMD acceleration: Uses SSE4.2, AVX2, or NEON instructions when available for blazing-fast searches
- Memory-mapped I/O: Maximizes throughput when processing large files
- Multi-threaded search: Automatically parallelizes searches across available CPU cores
- Regex support: POSIX Extended Regular Expression searching
- Multiple pattern search: Efficiently search for multiple patterns simultaneously using Aho-Corasick
- Recursive directory search: Skip binary files and common non-code directories
- Gitignore support: Respect
.gitignorefiles during recursive search with--gitignore - Stdin pattern input: Read patterns from stdin with
-f -for seamless pipeline integration - Colored output: Highlights matches for better readability
- UI/UX refresh (v2.2): New terminal color palette, clearer
-oline index styling, and a redesigned help screen - Specialized algorithms: Optimized handling for single-character and short patterns
- Match Limiting: Stop searching a file after a specific number of matching lines are found.
- Refined terminal-first UI with a cleaner, more legible color theme
- Better visual hierarchy in
-omode (filename, line index, match highlight) - Improved
--helplayout with grouped sections and clearer scanning
If you are on macOS and have Homebrew installed, you can install krep easily:
brew install krep# Clone the repository
git clone https://github.com/davidesantangelo/krep.git
cd krep
# Build and install
make
sudo make install
# uninstall
sudo make uninstallThe binary will be installed to /usr/local/bin/krep by default.
- GCC or compatible C compiler
- POSIX-compliant system (Linux, macOS, BSD)
- pthread support
Override default optimization settings in the Makefile:
# Disable architecture-specific optimizations
make ENABLE_ARCH_DETECTION=0krep [OPTIONS] PATTERN [FILE | DIRECTORY]
krep [OPTIONS] -e PATTERN [FILE | DIRECTORY]
krep [OPTIONS] -f FILE [FILE | DIRECTORY]
krep [OPTIONS] -s PATTERN STRING_TO_SEARCH
krep [OPTIONS] PATTERN < FILE
cat FILE | krep [OPTIONS] PATTERN
echo 'pattern' | krep -f - [FILE | DIRECTORY]Search for a fixed string in a file:
krep -F "value: 100%" config.iniSearch recursively:
krep -r "function" ./projectSearch recursively respecting .gitignore:
krep -r --gitignore "TODO" ./projectRead patterns from stdin (pipe-friendly):
echo 'pattern' | krep -f - target.txtWhole word search (matches only complete words):
krep -w 'cat' samples/text.enUse with piped input:
cat krep.c | krep 'c'-i, --ignore-caseCase-insensitive search-c, --countCount matching lines only-o, --only-matchingPrint only the matched parts of lines-e PATTERN, --pattern=PATTERNSpecify pattern(s). Can be used multiple times.-f FILE, --file=FILERead patterns from FILE, one per line. Use-for stdin.-m NUM, --max-count=NUMStop searching each file after finding NUM matching lines.-E, --extended-regexpUse POSIX Extended Regular Expressions-F, --fixed-stringsInterpret pattern as fixed string(s) (default unless -E is used)-r, --recursiveRecursively search directories--gitignoreRespect.gitignorefiles during recursive search--algo=ALGOForce search algorithm:auto(default),bm(Boyer-Moore),kmp(KMP)-t NUM, --threads=NUMUse NUM threads for file search (default: auto)-s STRING, --string=STRINGSearch in the provided STRING instead of file(s)-w, --word-regexpMatch only whole words--color[=WHEN]Control color output ('always', 'never', 'auto')--no-simdExplicitly disable SIMD acceleration-v, --versionShow version information-h, --helpShow help message
Benchmarks are run with the official dataset:
curl -LO 'https://burntsushi.net/stuff/subtitles2016-sample.en.gz'
gzip -dk subtitles2016-sample.en.gzYou can reproduce the krep vs ripgrep comparison with:
make bench-rg
# optional: RUNS=7 bash test/benchmark_krep_vs_rg.sh Sherlock| Pattern | krep avg real (s) | ripgrep avg real (s) | Speedup |
|---|---|---|---|
the |
0.175714 | 0.330000 | 1.88x |
Sherlock |
0.041429 | 0.080000 | 1.93x |
Measured on macOS ARM64 with test/benchmark_krep_vs_rg.sh. Results vary by CPU, storage and cache state.
Krep achieves its high performance through several key techniques:
Krep automatically selects the optimal search algorithm based on the pattern and available hardware:
- Boyer-Moore-Horspool for most literal string searches
- Knuth-Morris-Pratt (KMP) for very short patterns and repetitive patterns
- memchr optimization for single-character patterns
- SIMD Acceleration (SSE4.2, AVX2, or NEON) for compatible hardware
- Regex Engine for regular expression patterns
- Aho-Corasick for efficient multiple pattern matching (auto-selected with multiple
-epatterns)
Use --algo=bm or --algo=kmp to override the automatic selection for single-pattern literal searches.
Krep utilizes parallel processing to dramatically speed up searches:
- Automatically detects available CPU cores
- Divides large files into chunks for parallel processing
- Implements thread pooling for maximum efficiency
- Optimized thread count selection based on file size
- Careful boundary handling to ensure no matches are missed
Instead of traditional read operations:
- Memory maps files for direct access by the CPU
- Significantly reduces I/O overhead
- Enables CPU cache optimization
- Progressive prefetching for larger files
- Zero-copy architecture where possible
- Efficient match position tracking
- Lock-free aggregation of results
When using recursive search (-r), Krep automatically:
- Skips common binary file types
- Ignores version control directories (
.git,.svn) - Bypasses dependency directories (
node_modules,venv) - Detects binary content to avoid searching non-text files
Contributions are welcome! Please feel free to submit a Pull Request.
- Davide Santangelo - GitHub
This project is licensed under the BSD-2 License - see the LICENSE file for details.
Copyright © 2025 Davide Santangelo