LoginSignup
2
2

More than 5 years have passed since last update.

macOS の grep が遅い

Last updated at Posted at 2017-03-16

macOS の grep が遅いので計測したメモ。
OS は、macOS Sierra Version 10.12.3 というバージョンでした。

適当なデータがなかったので、こちらから拝借したcsvを少し加工して ken.csv として利用。
http://www.post.japanpost.jp/zipcode/dl/roman-zip.html

grep (BSD grep) 2.5.1-FreeBSD

BSD 版の grep です。多分もともと入っているやつ。

Average: 0.336

sh -c '\grep -i aoyama ken.csv > /dev/null'  0.32s user 0.01s system 96% cpu 0.347 total
sh -c '\grep -i aoyama ken.csv > /dev/null'  0.32s user 0.01s system 97% cpu 0.339 total
sh -c '\grep -i aoyama ken.csv > /dev/null'  0.30s user 0.01s system 97% cpu 0.322 total
sh -c '\grep -i aoyama ken.csv > /dev/null'  0.31s user 0.01s system 96% cpu 0.333 total
sh -c '\grep -i aoyama ken.csv > /dev/null'  0.31s user 0.01s system 97% cpu 0.336 total

ggrep (GNU grep) 2.28

GNU 版の grep です。Homebrew でインストールしました。

brew update
brew tap homebrew/dupes
brew install homebrew/dupes/grep

Average: 0.0176

sh -c '\ggrep -i aoyama ken.csv > /dev/null'  0.01s user 0.01s system 63% cpu 0.025 total
sh -c '\ggrep -i aoyama ken.csv > /dev/null'  0.01s user 0.01s system 61% cpu 0.021 total
sh -c '\ggrep -i aoyama ken.csv > /dev/null'  0.00s user 0.00s system 59% cpu 0.014 total
sh -c '\ggrep -i aoyama ken.csv > /dev/null'  0.00s user 0.00s system 56% cpu 0.015 total
sh -c '\ggrep -i aoyama ken.csv > /dev/null'  0.00s user 0.00s system 53% cpu 0.017 total

LANG=C ggrep

LANG=C 付き。

Average: 0.0136

sh -c 'LANG=C \ggrep -i aoyama ken.csv > /dev/null'  0.00s user 0.00s system 59% cpu 0.013 total
sh -c 'LANG=C \ggrep -i aoyama ken.csv > /dev/null'  0.00s user 0.00s system 65% cpu 0.014 total
sh -c 'LANG=C \ggrep -i aoyama ken.csv > /dev/null'  0.00s user 0.00s system 60% cpu 0.013 total
sh -c 'LANG=C \ggrep -i aoyama ken.csv > /dev/null'  0.01s user 0.01s system 59% cpu 0.025 total
sh -c 'LANG=C \ggrep -i aoyama ken.csv > /dev/null'  0.00s user 0.00s system 61% cpu 0.014 total

ag (The Silver Searcher)

@sugitk さんからコメントをいただいたので、メモを追加。
Homebrew でインストールしました。

brew install the_silver_searcher
ag --version
ag version 1.0.2

Features:
  +jit +lzma +zlib

Average: 0.0723

sh -c 'ag -i aoyama ken.csv > /dev/null'  0.04s user 0.02s system 86% cpu 0.076 total
sh -c 'ag -i aoyama ken.csv > /dev/null'  0.05s user 0.02s system 85% cpu 0.090 total
sh -c 'ag -i aoyama ken.csv > /dev/null'  0.04s user 0.02s system 87% cpu 0.070 total
sh -c 'ag -i aoyama ken.csv > /dev/null'  0.04s user 0.02s system 87% cpu 0.071 total
sh -c 'ag -i aoyama ken.csv > /dev/null'  0.04s user 0.02s system 87% cpu 0.068 total
2
2
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
2
2