Re: About speed evaluation

2020-09-08 Thread Greg Wooledge
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  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.



Re: About speed evaluation

2020-09-06 Thread L A Walsh

On 2020/09/06 05:52, Oğuz wrote:

6 Eylül 2020 Pazar tarihinde almahdi  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' receiving all of the args and either:
1) executing as many as possible/invocation, or
2) executing 1 script for each 'item' that is listed by find?

   i.e. seems to be wanting to know tradeoffs between

   find   -exec func_in_script "{} ;"   AND
   find   -exec "bash -c func_in_script \"{}\" ;"
 AND
   find   printf0 | xargs -0 func_in_script where
  func is called in a loop for each arg passed to it

   That was my interpretation.  One note...in most cases, you aren't
calling 'pipe repeated'.  The pipe is at the end of the find, and is
created *once* between the output of find and the input of the next
program (ex. xargs)
   Given my interpretation (which may be incorrect), note that
the first 2, above, both require starting a new copy of bash
for each object found.  That load+start time will vary depending
on what OS you are using and what version of each OS.  You can't
really answer "how much" as there isn't a general answer, but
in almost all cases (likely all), the answer that only invokes
one post-processor on all the args (the one where all answers
are piped into xargs) will be ***significantly*** faster than any
implementation that calls the processing function repeatedly (as in
the first two examples, above).

   So the cryptic, one-word answer would be "***significantly***".


   This is my interpretation and answer to what appears to be
the question.


all work correctly, so this ask all just on speed evaluation or comparison



   Using relative speed, invoking the post-processor only once
would normally be the fastest answer, by far, "comparatively" speaking.


(1st answer suggest function inside script to be invoked by -exec
2nd answer suggest solution by some core utils pipings ).


--
This needs some grammar, I didn't understand it all.
  


- Linda





Re: About speed evaluation

2020-09-06 Thread Oğuz
6 Eylül 2020 Pazar tarihinde almahdi  yazdı:

> How slower find -exec repetitively calling bash -c'' for invoking a
> function
> inside, compare to pipe repeated
>
> such this
> https://stackoverflow.com/questions/4793892/recursively-
> rename-files-using-find-and-sed
> all work correctly, so this ask all just on speed evaluation or comparison
>
> (1st answer suggest function inside script to be invoked by -exec
> 2nd answer suggest solution by some core utils pipings )
>
>
>
This needs some grammar, I didn't understand it all.


>
> --
> Sent from: http://gnu-bash.2382.n7.nabble.com/
>
>

-- 
Oğuz


About speed evaluation

2020-09-05 Thread almahdi
How slower find -exec repetitively calling bash -c'' for invoking a function
inside, compare to pipe repeated

such this 
https://stackoverflow.com/questions/4793892/recursively-rename-files-using-find-and-sed
all work correctly, so this ask all just on speed evaluation or comparison

(1st answer suggest function inside script to be invoked by -exec
2nd answer suggest solution by some core utils pipings )



--
Sent from: http://gnu-bash.2382.n7.nabble.com/