On Jan 10, 2008 2:16 PM, Mike Miller <<a href="mailto:mbmiller@taxa.epi.umn.edu">mbmiller@taxa.epi.umn.edu</a>> wrote:<br>[snip, with slightly less zeal :^) ]<br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I wonder how the various methods compare in speed. With a lot of files they must all be pretty slow, so speed is important.<br></blockquote></div><br>A worthy question!<br><br><div style="margin-left: 40px;">% find . | wc -l
<br>22531<br>% time perl -MFile::Find::Rule -MList::Util=max -le 'print scalar localtime(max map { (stat($_))[9] } find->in("."))'<br>Thu Jan 10 15:20:58 2008<br>real 0m1.122s<br>user 0m0.918s<br>
sys 0m0.203s<br><br>% perl -le 'print 1000 * 1.122 / 22531' <br>0.0497980560117172<br></div><br>So that's about 50 usec per file. Comparing with find + awk:<br><br><div style="margin-left: 40px;">% find . -type f -printf "%T@\n" | awk '{ if ($1 > the_max) { the_max = $1; } } END { print the_max }'
<br>1200000058<br>% time !!<br>time find . -type f -printf "%T@\n" | awk '{ if ($1 > the_max) { the_max = $1; } } END { print the_max }'<br>1200000058<br><br>real 0m0.168s<br>user 0m0.071s<br>sys
0m0.116s<br>% perl -le 'print 1000000 * 0.168 / 22531'<br>7.45639341351915<br></div><br>So something like 7usec per file. And just for grins (that's a lot of zeroes!):<br><br><div style="margin-left: 40px;">% perl -le 'print scalar localtime (1200000000)'
<br>Thu Jan 10 15:20:00 2008<br>% perl -le 'print scalar localtime (1300000000)'<br>Sun Mar 13 01:06:40 2011<br><br></div>Mark your calendars, nerds.<br><br>