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.
Support for ARM NEON, SSE4.2 and AVX2 instructions with specialized optimizations for short patterns and intelligent fallbacks.
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.
Powerful POSIX regular expression matching for complex pattern searching with the same high performance.
# Basic search
$ krep "error" system.log
# Case-insensitive search with 8 threads
$ krep -i -t 8 "ERROR" large_logfile.log
# Regular expression search
$ krep -r "[Ee]rror: .*" system.log
# Count occurrences only
$ krep -c "TODO" *.c
# Search within a string
$ krep -s "Hello" "Hello world"
# Recursive directory search
$ krep -r "TODO" ./project
# Pattern specification with -e (useful for patterns starting with dash)
$ krep -e "-pattern" file.txt
// Dynamic algorithm selection
if (pattern_len < 3) {
// KMP is more efficient for very short patterns
match_count = kmp_search(...);
} else {
// Use SIMD (with fallback) or Boyer-Moore for medium length patterns
#ifdef __ARM_NEON
match_count = neon_search(...); // Optimized ARM NEON implementation
#elif defined(__AVX2__)
match_count = simd_avx2_search(...); // Currently falls back to Boyer-Moore
#elif defined(__SSE4_2__)
match_count = simd_sse42_search(...); // Currently falls back to Boyer-Moore
#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 | 3.5x |
grep | 2.73 | 366 | 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