Tagged: ag

How to Use Hyperfine. Example: Compare the Performance of rg and ag

How to Use Hyperfine to Compare the Performance of rg and ag

What is Hyperfine?

Hyperfine is a command-line tool that allows you to measure and compare the performance of other commands. It is particularly useful for evaluating the execution speed of different commands or scripts, providing detailed statistics such as average time, standard deviation, and execution time range.

Introduction to rg (ripgrep)

Ripgrep, often abbreviated as rg, is an ultra-fast text search tool. It is designed to quickly scan files and directories for specific patterns. Ripgrep is known for its speed and its ability to ignore irrelevant files, such as those in .git or node_modules directories.

Introduction to ag (The Silver Searcher)

The Silver Searcher, or ag, is another text search tool, similar to ack, but faster. It is optimized for searching within code projects, automatically ignoring irrelevant files and directories. Although it is fast, it is often outperformed by rg in terms of performance.

Performance Comparison with Hyperfine

To compare the performance of rg and ag, we can use Hyperfine with the following command:

hyperfine --warmup 3 'rg -i "Olivier" -g "*php*" .' 'ag -i "Olivier" -G "php"'

The results show that rg is significantly faster than ag:

  • rg has an average execution time of 256.6 ms.
  • ag has an average execution time of 910.3 ms.

In summary, rg is approximately 3.55 times faster than ag in this scenario.

Why Use rg Instead of ag?

The comparison conducted with Hyperfine clearly demonstrates that rg outperforms ag for text searching. If speed is an important criterion for you, rg is therefore an obvious choice. Additionally, rg offers better handling of ignored files and smoother integration with modern development tools.

In conclusion, if you are looking for a fast and efficient text search tool, rg is an excellent option, especially when working on large-scale projects where every millisecond counts.