home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10716 < prev    next >
Encoding:
Text File  |  1992-09-03  |  4.4 KB  |  94 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!casbah.acns.nwu.edu!navarra
  3. From: navarra@casbah.acns.nwu.edu (John Navarra)
  4. Subject: Question: which is faster 'find -exec' or 'find | xargs' ??
  5. Message-ID: <1992Sep4.041033.23158@news.acns.nwu.edu>
  6. Sender: usenet@news.acns.nwu.edu (Usenet on news.acns)
  7. Organization: Northwestern University, Evanston Illinois.
  8. Date: Fri, 4 Sep 1992 04:10:33 GMT
  9. Lines: 83
  10.  
  11.  
  12. I was experimenting with find and xargs. I issued the command
  13.   find . -exec ls -ld {} \;
  14. and the command
  15.   find . -print | xargs ls -ld
  16. and found they gave the same results. However, I noticed the execution
  17. times for the two were MUCH different. If I time the two commands
  18. from my home directory, which contains many files, here is what I get:
  19.  
  20. [casbah:47] ~ -> time find . -exec ls -ld {} \; > /dev/null
  21.       287.4 real        39.1 user       219.9 sys
  22. [casbah:48] ~ -> time find . -print | xargs ls -ld > /dev/null
  23.        47.6 real         0.0 user        17.3 sys
  24.  
  25.  
  26. Question: why is the xargs command MUCH faster?
  27.  
  28. While running the following commands, I ran ps -j many times. Here are some
  29. of those results:
  30.  
  31. using exec:
  32. PPID   PID  PGID   SID TT TPGID  STAT   UID  TIME COMMAND
  33.  9119  9120  9120  9120 r6 21398   SOE   453  0:03 -bash (bash)
  34.  9120 21383 21383  9120 r6 21398    SE   453  0:00 find . -exec ls -ld {} ;
  35.  9120 21398 21398  9120 r6 21398    RE   453  0:00 ps -j
  36. 21383 21401 21383  9120 r6 21398    RE   453  0:00 ls -ld ./.elm/lsig.bak
  37.  PPID   PID  PGID   SID TT TPGID  STAT   UID  TIME COMMAND
  38.  9119  9120  9120  9120 r6 21409   SOE   453  0:03 -bash (bash)
  39.  9120 21383 21383  9120 r6 21409    SE   453  0:00 find . -exec ls -ld {} ;
  40.  9120 21409 21409  9120 r6 21409    RE   453  0:00 ps -j
  41. 21383 21412 21383  9120 r6 21409    RE   453  0:00 ls -ld ./bin/file_clean
  42.  PPID   PID  PGID   SID TT TPGID  STAT   UID  TIME COMMAND
  43.  9119  9120  9120  9120 r6 21422   SOE   453  0:03 -bash (bash)
  44.  9120 21383 21383  9120 r6 21422    SE   453  0:00 find . -exec ls -ld {} ;
  45.  9120 21422 21422  9120 r6 21422    RE   453  0:00 ps -j
  46. 21383 21426 21383  9120 r6 21422    RE   453  0:00 ls -ld ./bin/lastarg
  47.  
  48. In this case, bash is the parent to the find command, and find is the
  49. parent to the ls -ld filename command. Thus, there is one find process,
  50. plus X ls -ld filename processes where X is the number of files to be
  51. listed. (obviously, I was not fast enough to capture all of them)
  52.   
  53.  
  54. using xargs:
  55.  PPID   PID  PGID   SID TT TPGID  STAT   UID  TIME COMMAND
  56.  9119  9120  9120  9120 r6 21857   SOE   453  0:06 -bash (bash)
  57.  9120 21817 21817  9120 r6 21857    SE   453  0:02 find . -print
  58.  9120 21818 21817  9120 r6 21857    SE   453  0:03 xargs ls -ld
  59.  9120 21857 21857  9120 r6 21857    RE   453  0:00 ps -j
  60.  PPID   PID  PGID   SID TT TPGID  STAT   UID  TIME COMMAND
  61.  9119  9120  9120  9120 r6 21867   SOE   453  0:06 -bash (bash)
  62.  9120 21817 21817  9120 r6 21867    SE   453  0:02 find . -print
  63.  9120 21818 21817  9120 r6 21867    SE   453  0:03 xargs ls -ld
  64.  9120 21867 21867  9120 r6 21867    RE   453  0:00 ps -j
  65. 21818 21868 21817  9120 r6 21867    RE   453  0:00 ls -ld ./awk/shellreport.naw
  66.  PPID   PID  PGID   SID TT TPGID  STAT   UID  TIME COMMAND
  67.  9119  9120  9120  9120 r6 21900   SOE   453  0:07 -bash (bash)
  68.  9120 21817 21817  9120 r6 21900    RE   453  0:04 find . -print
  69.  9120 21818 21817  9120 r6 21900    RE   453  0:07 xargs ls -ld
  70.  9120 21900 21900  9120 r6 21900    RE   453  0:00 ps -j
  71. 21818 21908 21817  9120 r6 21905    RE   453  0:00 ls -ld ./perl/perl_info/docs
  72.  
  73. In this case, bash is the parent of both the find and xargs commands. And
  74. xargs is the parent of the ls -ld filename commands. Thus, there is
  75. one find process, one xargs process, and X ls -ld processes (again, where
  76. X is the number of files to be listed.)
  77.  
  78. The way I count it, the xargs command has one extra process, the overhead
  79. of setting up a pipe, and the fact that two commands are being used vs
  80. one. But, for some reason the xargs command was MUCH faster than the
  81. find -exec command.  
  82.  
  83. What's the deal? From what I can gather, find -exec will write the
  84. stdout X times in this case where xargs writes in chunks. Is that
  85. correct?
  86.  
  87.  
  88. -tms 
  89. -- 
  90. You can get further with a kind word | You can get further with a kind word
  91. and a gun than a kind word alone.    | and a phaser than a kind word and a gun.
  92.           --al capone                |           -- John Navarra
  93. =======From the Lab of the MaD ScIenTIst....navarra@casbah.acns.nwu.edu========
  94.