0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

高速なgrepといえばripgrep

Posted at

メリークリスマス!開発環境を紹介します Advent Calendar 2024です。

よく使うコマンドを紹介したくて登録しました。 
隙間があれば他にも書こうと思います。隙間産業!

ripgrep

紹介するのはripgrepです。
今更説明がいるのかと思うくらい有名なプロジェクトです。

grepはご存知のとおり、ファイルを行単位で検索するコマンドです。
ファイルと正規表現を入力として受け取り、正規表現にマッチするファイルの行を出力します。

ファイルの巨大化に伴い、より高速なgrepが求められるようになりました。
そこで誕生したのが、ag(The Silver Searcher)やrg(ripgrep)などです。
現在ではripgrepのほうがより広く使われる印象です。

実行例

インストールするとコマンドrgでripgrepが使えます。
デフォルトの色付けやフォーマットも見やすい印象です。

image.png

grepとの速度比較

手元の環境にて、キャッシュバイナリを含む2.6GBのレポジトリで「todo」を検索しました。
なるべく検索条件を近づけるためにrgにオプションをつけています。

image.png

image.png

  • grep
    • 1759 ms
  • ripgrep
    • 151.0 ms

実に11倍以上の差がついています。

まとめ

ripgrepの紹介でした。
grepの代わりに高速なripgrepを使おう!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?