krep

A blazingly fast string search utility for performance-critical applications

3.5x Faster than grep

Features

High Performance

Optimized algorithms and memory-mapped file I/O deliver up to 5x faster search speeds than traditional tools.

Hardware Acceleration

Support for ARM NEON, SSE4.2 and AVX2 instructions with specialized optimizations for short patterns and intelligent fallbacks.

Multi-Threading

Parallel processing for large files with intelligent chunk boundaries to ensure accurate results.

Smart Algorithm Selection

Dynamically chooses the best algorithm based on pattern characteristics and hardware capabilities.

Memory Efficient

Uses memory mapping and minimal allocations to reduce memory overhead while maintaining performance.

Simple Interface

Familiar command-line interface that's easy to use while providing powerful capabilities.

Regular Expression Support

Powerful POSIX regular expression matching for complex pattern searching with the same high performance.

Usage Examples

# 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

Algorithm Selection Logic

// 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
}

Performance

krep consistently outperforms traditional search tools across various file sizes and search patterns.

Performance Comparison

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

Algorithm Performance by Pattern Length

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.

Installation

Clone the Repository

git clone https://github.com/davidesantangelo/krep.git
cd krep

Build

make

Install

sudo make install

Prerequisites

  • • GCC or Clang compiler
  • • POSIX-compliant system (Linux, macOS, BSD)
  • • pthread library