In article <1992Sep4.041033.23158@news.acns.nwu.edu>, navarra@casbah.acns.nwu.edu (John Navarra) writes:
|>
|> I was experimenting with find and xargs. I issued the command
|> find . -exec ls -ld {} \;
|> and the command
|> find . -print | xargs ls -ld
|> and found they gave the same results. However, I noticed the execution
|> times for the two were MUCH different. If I time the two commands
|> from my home directory, which contains many files, here is what I get:
|>
|> [casbah:47] ~ -> time find . -exec ls -ld {} \; > /dev/null
|> 287.4 real 39.1 user 219.9 sys
|> [casbah:48] ~ -> time find . -print | xargs ls -ld > /dev/null
|> 47.6 real 0.0 user 17.3 sys
|>
|>
|> Question: why is the xargs command MUCH faster?
... [Lot's of stuff deleted]
Point 1:
The time command for the second case (with xargs) is only timing the find command, ignoring the time spent doing the xargs ls command.
If you want to time the pipeline try timing a parent shell which executes the pipeline. There will ofcourse be some overhead concerning the startup of the shell, but that is constant and therefore tends to zero importance as the size of the job being done by the shell script increases.
#!/bin/sh
find . -print | xargs ls -ld > /dev/null
Also, if you run the above script a few times, things will speed up due to the OS buffering mem, file descriptors et al. 4 or 5 goes should be enough to get a steady result on an evenly loaded machine.
Point 2:
I'm not so sure about this (haven't seen the source for "find" but ...) If the
-exec primitive is to be believed then the find process must fork and exec an ls
for every line of output from the find. That's an awful lot of work! Which
version of fork you're using and on which machine will make a difference also,
though not as dramatically as the difference between using a pipeline, and doing
for/exec for everyline of output.
Share and enjoy ...
--Rob.
|>
|> What's the deal? From what I can gather, find -exec will write the
|> stdout X times in this case where xargs writes in chunks. Is that
|> correct?
|>
--
Robert P K Lyle #include <std_disclaimer.h> **********************