Re: why is perl -e 'unlink(glob("*"))' so much faster than rm ?



ewaguespack@xxxxxxxxx wrote:
i had a situation that required that i remove several thousand zero
byte files, and i tried this first:

# find . -type f -exec rm -f {} \;

this was taking ages, so on a hunch I decided to try this to see it I
got any better results:

That fires up a separate rm process for each file. Using strace -f, it
looks like this involves 99 system calls per rm (not counting the ones done
in the parent process), only one of which is related to the actual unlink.

# perl -e 'unlink(glob("*"))'

This doesn't do the -type f checking. If you don't really need to
do the -type f checking, why did you use find (rather than "rm -f *")
in the first place? One possible reason is if that gives you an argument
list too long error. I use the perl -le 'unlink(glob($ARGV[0]))' construct
frequently for just that reason.

surprisingly the perl unlink took about a quarter of a second to remove
1000 files versus 30 seconds with find / rm

That really surprises me. Not because of the difference between the two
methods, but because both of them are about 20 times slower for you than
they are on my not-particularly fast machine.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
.



Relevant Pages

  • Re: why is perl -e unlink(glob("*")) so much faster than rm ?
    ... so on a hunch I decided to try this to see it I ... in the parent process), only one of which is related to the actual unlink. ... One possible reason is if that gives you an argument ... when I ran the rm command on an idle server it was much faster. ...
    (comp.lang.perl.misc)
  • I need a philosophical opinion ...
    ... I would be delighted if someone smarter than me would tear apart my ... little thesis My maths skills are borken ... dentote chaitins omega differently (with reason) ... ... strong hunch I can explain why ... ...
    (sci.physics.relativity)
  • Re: Trying to do some signal handling ..
    ... The exit status is returned by waitin the parent process. ... > for some reason .. ... > int main ... > void dispDirFiles ...
    (comp.unix.programmer)
  • Re: I need a philosophical opinion ...
    ... i apologise for my esoteric notation, it's a bit cantoresque and I ... dentote chaitins omega differently (with reason) ... ... strong hunch I can explain why ... ...
    (sci.physics.relativity)
  • Re: Ruby doesnt implement x++ for Fixnums because ???
    ... That's my hunch, at least. ... would be strange. ... But there's certainly no reason it can't be done, ... have one Ruby implementer on this thread attesting that it can. ...
    (comp.lang.ruby)