bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#23321: [PROPOSED PATCH] grep: /dev/null output speedup


From: arnold
Subject: bug#23321: [PROPOSED PATCH] grep: /dev/null output speedup
Date: Thu, 21 Apr 2016 00:45:49 -0600
User-agent: Heirloom mailx 12.4 7/29/08

Paul Eggert <address@hidden> wrote:

> This sped up 'seq 10000000000 | grep . >/dev/null' by a factor of
> 380,000 on my platform (Fedora 23, x86-64, AMD Phenom II X4 910e,
> en_US.UTF-8 locale).
> +      else if (S_ISCHR (tmp_stat.st_mode))
> +        {
> +          struct stat null_stat;
> +          if (stat ("/dev/null", &null_stat) == 0
> +              && SAME_INODE (tmp_stat, null_stat))

Testing for same inode is likely to work but not guaranteed. I think
it'd be better to compare the major and minor device numbers on the two
stat buffers. If they're equal then you know for sure you have a null
device in hand.

(Consider someone who is root and does a 'mknod MA MI /tmp/null' where
MA and MI are the major and minor device numbers for /dev/null. grep
into such a /tmp/null would not enjoy the speedup as you've coded it.
And I know that practically speaking this is unlikely, I'm coming at it
more from a perspectgive of bullet-proofing the code.)

My two cents worth, of course.

Thanks,

Arnold





reply via email to

[Prev in Thread] Current Thread [Next in Thread]