krep

A blazingly fast string search utility for performance-critical applications

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

Automatically leverages SSE4.2 and AVX2 instructions when available for maximum throughput.

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.

Usage Examples

# 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"

Algorithm Selection Logic

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

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 5.0x
ripgrep 1.48 676 2.0x
grep 2.95 339 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