brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (10/25/90)
Great, just great. I've now seen three messages all based on Bill's results here. I said: > | No, it's not. Try head -1 | sed 's/.../.../'; cat. And he did: > $ time { head -1; sed 's/foo/bar/'; cat; } < x.tmp > /dev/null Can people read? Of course that's going to be slow: it shoves the whole file through sed. > How 'bout that! The overhead of all the other stuff made it slower. I > guess I'll vote for using just plain sed, because it's easier, faster, > uses less memory, etc. I didn't create a multi-megabyte file, so there > may be a break even point, but I wouldn't bet on it. These incorrect conclusions are based on your tests of something entirely different from what I said. Now for some real timings: Script started on Wed Oct 24 15:34:31 EDT 1990 csh> time 0.1u 0.3s 0:05 8% 0+232k 0+0io 0pf+0w csh> sed '1s/foo/bar/g' < /etc/hosts > tsed csh> time 1.4u 0.8s 0:30 7% 0+232k 7+39io 7pf+0w csh> ( head -1 | sed 's/foo/bar/g' ; cat ) < /etc/hosts > tcat csh> time 1.5u 1.2s 0:58 4% 0+232k 7+78io 7pf+0w Script done on Wed Oct 24 15:36:07 EDT 1990 sed takes 1.3u and 0.5s. The cat-based solution takes 0.1u and 0.4s. And /etc/hosts isn't very big. For really large files (several megabytes) the margin approaches 12x. Can we all agree here that sed is inefficient? (The above timings are from a Sun 4, by the way.) ---Dan