A blazingly fast string search utility for performance-critical applications
Optimized algorithms and memory-mapped file I/O deliver up to 5x faster search speeds than traditional tools.
Automatically leverages SSE4.2 and AVX2 instructions when available for maximum throughput.
Parallel processing for large files with intelligent chunk boundaries to ensure accurate results.
Dynamically chooses the best algorithm based on pattern characteristics and hardware capabilities.
Uses memory mapping and minimal allocations to reduce memory overhead while maintaining performance.
Familiar command-line interface that's easy to use while providing powerful capabilities.
# Basic search
$ krep "error" system.log
# Case-insensitive search with 8 threads
$ krep -i -t 8 "ERROR" large_logfile.log
# Count occurrences only
$ krep -c "TODO" *.c
# Search within a string
$ krep -s "Hello" "Hello world"
// Dynamic algorithm selection
if (pattern_len < 3) {
// KMP is more efficient for very short patterns
match_count = kmp_search(...);
} else if (pattern_len > 16) {
// Rabin-Karp works well for longer patterns
match_count = rabin_karp_search(...);
} else {
// Use SIMD or Boyer-Moore for medium length patterns
#ifdef __AVX2__
match_count = avx2_search(...);
#elif defined(__SSE4_2__)
match_count = simd_search(...);
#else
match_count = boyer_moore_search(...);
#endif
}
krep consistently outperforms traditional search tools across various file sizes and search patterns.
Tool | Time (seconds) | Speed (MB/s) | Relative Performance |
---|---|---|---|
krep | 0.78 | 1,282 | 5.0x |
ripgrep | 1.48 | 676 | 2.0x |
grep | 2.95 | 339 | 1.0x |
Searching a 1GB text file for a common pattern
krep's performance advantages are particularly noticeable when processing large files on modern multi-core systems, where it can fully leverage hardware capabilities and parallel processing.
git clone https://github.com/davidesantangelo/krep.git
cd krep
make
sudo make install