Bash Party: RIP exec inside find

I use find too frequently to search for things, and most often, spawn some external command using -exec to process the results individually. This ars article gave a pretty neat idea to speed up find/exec to order of 10+ times; the technique uses xargs to remove the execution loop.

This is a sample run from my Ubuntu box:

$ time find . -name '*.properties' -exec wc -l {} \; -print
...
real    0m1.788s
user    0m0.096s
sys    0m0.120s

$ time find . -name '*.properties' -print0 | xargs -0 wc -l
 ...
real    0m0.169s
user    0m0.044s
sys    0m0.096s

Whoa!

Advertisements

About forrestrunning
Code Chaser

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: