From: Ralph Corderoy <ralph@inputplus.co.uk>
To: coff@tuhs.org
Subject: [COFF] Re: Requesting thoughts on extended regular expressions in grep.
Date: Sat, 04 Mar 2023 10:07:17 +0000 [thread overview]
Message-ID: <20230304100717.E8F882021A@orac.inputplus.co.uk> (raw)
In-Reply-To: <c4e87cee-d04f-50be-cb91-edf1b24eaf07@spamtrap.tnetconsulting.net>
Hi Grant,
> Suppose I have the following two lines:
>
> aaa aaa
> aaa bbb
>
> Does the following RE w/ back-reference introduce a big performance
> penalty?
>
> (aaa|bbb) \1
>
> As in:
>
> % echo "aaa aaa" | egrep "(aaa|bbb) \1"
> aaa aaa
You could measure the number of CPU instructions and experiment.
$ echo xyzaaa aaaxyz >f
$ ticks() { LC_ALL=C perf stat -e instructions egrep "$@"; }
$
$ ticks '(aaa|bbb) \1' <f
xyzaaa aaaxyz
Performance counter stats for 'egrep (aaa|bbb) \1':
2790889 instructions:u
0.009146904 seconds time elapsed
0.009178000 seconds user
0.000000000 seconds sys
$
Bear in mind that egreps differ, even within GNU egrep, say, over time.
$ LC_ALL=C perf stat -e instructions egrep '(aaa|bbb) \1' f
xyzaaa aaaxyz
...
2795836 instructions:u
...
$ LC_ALL=C perf stat -e instructions perl -ne '/(aaa|bbb) \1/ and print' f
xyzaaa aaaxyz
...
2563488 instructions:u
...
$ LC_ALL=C perf stat -e instructions sed -nr '/(aaa|bbb) \1/p' f
xyzaaa aaaxyz
...
610213 instructions:u
...
$
--
Cheers, Ralph.
next prev parent reply other threads:[~2023-03-04 10:07 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 18:54 [COFF] " Grant Taylor via COFF
2023-03-02 19:23 ` [COFF] " Clem Cole
2023-03-02 19:38 ` Grant Taylor via COFF
2023-03-02 23:01 ` Stuff Received
2023-03-02 23:46 ` Steffen Nurpmeso
2023-03-03 1:08 ` Grant Taylor via COFF
2023-03-03 2:10 ` Dave Horsfall
2023-03-03 3:34 ` Grant Taylor via COFF
2023-03-02 21:53 ` Dan Cross
2023-03-03 1:05 ` Grant Taylor via COFF
2023-03-03 3:04 ` Dan Cross
2023-03-03 3:53 ` Grant Taylor via COFF
2023-03-03 13:47 ` Dan Cross
2023-03-03 19:26 ` Grant Taylor via COFF
2023-03-03 10:59 ` Ralph Corderoy
2023-03-03 13:11 ` Dan Cross
2023-03-03 13:42 ` Ralph Corderoy
2023-03-03 19:19 ` Grant Taylor via COFF
2023-03-04 10:15 ` [COFF] Reading PDFs on a mobile. (Was: Requesting thoughts on extended regular expressions in grep.) Ralph Corderoy
2023-03-07 21:49 ` [COFF] " Tomasz Rola
2023-03-07 22:46 ` Tomasz Rola
2023-03-03 16:12 ` [COFF] Re: Requesting thoughts on extended regular expressions in grep Dave Horsfall
2023-03-03 17:13 ` Dan Cross
2023-03-03 17:38 ` Ralph Corderoy
2023-03-03 19:09 ` Dan Cross
2023-03-03 19:36 ` Grant Taylor via COFF
2023-03-04 10:26 ` Ralph Corderoy
2023-03-03 19:06 ` Grant Taylor via COFF
2023-03-03 19:31 ` Dan Cross
2023-03-04 10:07 ` Ralph Corderoy [this message]
2023-03-06 10:01 ` Ed Bradford
2023-03-06 21:01 ` Dan Cross
2023-03-06 21:49 ` Steffen Nurpmeso
2023-03-07 1:43 ` Larry McVoy
2023-03-07 4:01 ` Ed Bradford
2023-03-07 11:39 ` [COFF] " Ralph Corderoy
2023-03-07 18:31 ` [COFF] " Grant Taylor via COFF
2023-03-08 11:22 ` Ed Bradford
2023-03-07 16:14 ` Dan Cross
2023-03-07 17:34 ` [COFF] " Ralph Corderoy
2023-03-07 18:33 ` [COFF] " Dan Cross
2023-03-07 4:19 ` Ed Bradford
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230304100717.E8F882021A@orac.inputplus.co.uk \
--to=ralph@inputplus.co.uk \
--cc=coff@tuhs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).