[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: About speed evaluation
From: |
Greg Wooledge |
Subject: |
Re: About speed evaluation |
Date: |
Tue, 8 Sep 2020 08:05:17 -0400 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Sun, Sep 06, 2020 at 12:06:26PM -0700, L A Walsh wrote:
> On 2020/09/06 05:52, Oğuz wrote:
> > 6 Eylül 2020 Pazar tarihinde almahdi <budikusasi@gmail.com> yazdı:
> >
> > > How slower find -exec repetitively calling bash -c'' for invoking a
> > > function
> > > inside, compare to pipe repeated
> ----
>
> How I read that (dunno if it is right) was:
> "How much slower is 'find -exec' than repetitively calling 'bash -c' for
> the purpose of invoke a function inside (the script or target of what
> 'exec' or '-c' executes) compared to piping all the answers to something
> like 'xargs' [...]
Yeah, I'm making a similar assumption. It would help if the email
actually contained the two pieces of code in question, because I can't
be bothered to go read some external web site to see what the question
is.
Even better would be a simple statement of the desired goal, without
any code, because chances are all of the code that's been written is
flawed.
Let's assume that we've got a function "func" defined in bash, and
that it only takes a single filename as an argument. Let's also assume
that we want to call it once for every file in a directory tree,
recursively.
The two recommended ways to do that are:
# (1)
export -f func
find . -type f -exec bash -c 'for f; do func "$f"; done' x {} +
# (2)
while IFS= read -r -d '' f; do
func "$f"
done < <(find . -type f -print0)
The second one requires GNU or BSD find.