3 ms·
Author of ripgrep here. It really just depends. The way I like to characterize `git grep` (at present) is that it has sharp performance cliffs. ripgrep has the
by burntsushi 3y ago
Author of ripgrep here.
It really just depends. The way I like to characterize `git grep` (at present) is that it has sharp performance cliffs. ripgrep has them too, to be sure, but I think it has fewer of them.
If you're just searching for a simple literal, `git grep` is decently fast:
$ git remote -v
origin git@github.com:torvalds/linux (fetch)
origin git@github.com:torvalds/linux (push)
$ git rev-parse HEAD
f1fcbaa18b28dec10281551dfe6ed3a3ed80e3d6
$ time LC_ALL=en_US.UTF-8 git grep -c -E 'PM_RESUME'
Documentation/dev-tools/sparse.rst:3
Documentation/translations/zh_CN/dev-tools/sparse.rst:3
Documentation/translations/zh_TW/sparse.txt:3
arch/arm/mach-omap2/omap-secure.h:1
arch/arm/mach-omap2/pm33xx-core.c:1
arch/x86/kernel/apm_32.c:1
drivers/input/mouse/cyapa.h:1
drivers/mtd/maps/pcmciamtd.c:1
drivers/net/wireless/intersil/hostap/hostap_cs.c:1
drivers/net/wwan/t7xx/t7xx_pci.c:15
drivers/net/wwan/t7xx/t7xx_reg.h:7
drivers/usb/mtu3/mtu3_hw_regs.h:1
include/uapi/linux/apm_bios.h:1
real 0.215
user 0.421
sys 1.226
maxmem 161 MB
faults 0
$ time rg -c 'PM_RESUME'
drivers/mtd/maps/pcmciamtd.c:1
drivers/net/wwan/t7xx/t7xx_reg.h:7
drivers/net/wwan/t7xx/t7xx_pci.c:15
drivers/net/wireless/intersil/hostap/hostap_cs.c:1
drivers/usb/mtu3/mtu3_hw_regs.h:1
drivers/input/mouse/cyapa.h:1
arch/x86/kernel/apm_32.c:1
Documentation/translations/zh_CN/dev-tools/sparse.rst:3
Documentation/translations/zh_TW/sparse.txt:3
Documentation/dev-tools/sparse.rst:3
arch/arm/mach-omap2/pm33xx-core.c:1
arch/arm/mach-omap2/omap-secure.h:1
include/uapi/linux/apm_bios.h:1
real 0.078
user 0.259
sys 0.577
maxmem 15 MB
faults 0
But if you switch it up and start adding regex things to your pattern, there can be substantial slowdowns:
$ time LC_ALL=C git grep -c -E '\w{5,}\s+PM_RESUME'
Documentation/dev-tools/sparse.rst:1
Documentation/translations/zh_CN/dev-tools/sparse.rst:1
Documentation/translations/zh_TW/sparse.txt:1
real 5.704
user 55.671
sys 0.585
maxmem 207 MB
faults 0
$ time LC_ALL=en_US.UTF-8 git grep -c -E '\w{5,}\s+PM_RESUME'
Documentation/dev-tools/sparse.rst:1
Documentation/translations/zh_CN/dev-tools/sparse.rst:1
Documentation/translations/zh_TW/sparse.txt:1
real 24.529
user 4:34.42
sys 0.753
maxmem 211 MB
faults 0
$ time LC_ALL=en_US.UTF-8 git grep -c -P '\w{5,}\s+PM_RESUME'
Documentation/dev-tools/sparse.rst:1
Documentation/translations/zh_CN/dev-tools/sparse.rst:1
Documentation/translations/zh_TW/sparse.txt:1
real 1.372
user 16.980
sys 0.647
maxmem 211 MB
faults 1
$ time rg -c '\w{5,}\s+PM_RESUME'
Documentation/translations/zh_CN/dev-tools/sparse.rst:1
Documentation/dev-tools/sparse.rst:1
Documentation/translations/zh_TW/sparse.txt:1
real 0.082
user 0.226
sys 0.612
maxmem 18 MB
faults 0
In the above cases, ripgrep has Unicode enabled. (It's enabled by default irrespective of locale settings. ripgrep doesn't interact with POSIX locales at all.)
- ctenb 3y agoThanks for clarifying! I use `git grep -IPn --color=always --recurse-submodules` many times a day, every day. I hasn't yet let me down, but I don't search for unicode when working on source code. I do use regex though, using the -P switch.