[Inevitable off-topic discussion ensues]

With a large amount of files (and with hundreds of directories, we can assume there are a large amount of files. Either that or someone has designed a very bad filesystem layout), using -exec with find can be substantially slower than using xargs. The reason being that -exec forks once for every file, whereas xargs will pack as many arguments on a single command line as possible. This is not only conceptually cleaner (imho), but like I said, with lots of files it's noticeably faster.

Update: Just to test my assertions, I ran a test to see what the difference was. As you can see, the directory I'm running this in has 29,388 files. Granted this benchmark might not be representative of the actual post, but the difference is quite dramatic. Maybe I've done something wrong:

$ time find ./ -type f | wc -l 29388 real 0m0.244s user 0m0.034s sys 0m0.181s $ time find ./ -type f -print0 | xargs -0 ls | wc -l 29388 real 0m1.049s user 0m0.420s sys 0m0.588s $ time find ./ -type f -exec ls '{}' \; | wc -l 29388 real 0m46.239s user 0m16.509s sys 0m25.974s

I ran each test multiple times, and posted the lowest time for each.


In reply to Re: Re: Re: greping for a word by revdiablo
in thread greping for a word by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.