Out of curiosity, I tested this on an Arch Linux system:
$ uname -r
4.4.5-1-ARCH
$ df -h .
Filesystem Size Used Avail Use% Mounted on
tmpfs 3.9G 720K 3.9G 1% /tmp
$ dd if=/dev/urandom bs=1M count=1K | base64 > foo
$ df -h .
Filesystem Size Used Avail Use% Mounted on
tmpfs 3.9G 1.4G 2.6G 35% /tmp
$ for i in {1..100}; do /usr/bin/time -f '%e' -ao grep.log grep -iq foobar foo; done
$ for i in {1..100}; do /usr/bin/time -f '%e' -ao egrep.log egrep -q '[fF][oO][oO][bB][aA][rR]' foo; done
$ grep --version
grep (GNU grep) 2.23
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
And then some stats courtesy of Is there a way to get the min, max, median, and average of a list of numbers in a single command?:
$ R -q -e "x <- read.csv('grep.log', header = F); summary(x); sd(x[ , 1])"
> x <- read.csv('grep.log', header = F); summary(x); sd(x[ , 1])
V1
Min. :1.330
1st Qu.:1.347
Median :1.360
Mean :1.362
3rd Qu.:1.370
Max. :1.440
[1] 0.02322725
>
>
$ R -q -e "x <- read.csv('egrep.log', header = F); summary(x); sd(x[ , 1])"
> x <- read.csv('egrep.log', header = F); summary(x); sd(x[ , 1])
V1
Min. :1.330
1st Qu.:1.340
Median :1.360
Mean :1.365
3rd Qu.:1.380
Max. :1.430
[1] 0.02320288
>
>
I'm on the en_GB.utf8
locale, but the times are nearly indistinguishable.
grep
's the other way around, to make sure you're not measuring the difference between disk caching of the flie. – EightBitTony Mar 14 '16 at 00:26egrep
is faster thangrep
until I setLANG=C
and then they're both roughly the same. – EightBitTony Mar 14 '16 at 00:39en_US.UTF-8
,Linux server 3.19.0-42-lowlatency #48~14.04.1-Ubuntu SMP PREEMPT Fri Dec 18 11:34:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
. That should be the answer, I guess. – tildearrow Mar 14 '16 at 00:42fgrep
too! – kojiro Mar 14 '16 at 10:32grep -i
: 0.044s,egrep
: 0.005s,fgrep
: 0.004s. – tildearrow Mar 14 '16 at 13:33egrep [wW][oO][rR][dD]
is not faster thangrep -i word
under the same locale and given file in in the buffer-cache. – arielf Mar 14 '16 at 20:36user
time (which does not include time waiting for disk). There is an order of magnitude in difference. – kasperd Mar 15 '16 at 11:17sort
suffer from the same issue. See also http://stackoverflow.com/questions/13819635 – Adrian Pronk Mar 19 '16 at 02:13