Path: utzoo!utgpu!watserv1!watmath!att!att!pacbell.com!ucsd!sdd.hp.com!uakari.primate.wisc.edu!crdgw1!sixhub!davidsen From: davidsen@sixhub.UUCP (Wm E. Davidsen Jr) Newsgroups: comp.unix.questions Subject: Re: edit first line of long file Message-ID: <2164@sixhub.UUCP> Date: 24 Oct 90 03:12:36 GMT References: <27338@shamash.cdc.com> <568@inews.intel.com> <4597:Oct2321:44:2190@kramden.acf.nyu.edu> Reply-To: davidsen@sixhub.UUCP (bill davidsen) Organization: *IX Public Access UNIX, Schenectady NY Lines: 53 In article <4597:Oct2321:44:2190@kramden.acf.nyu.edu> brnstnd@kramden.acf.nyu.edu (Dan Bernstein) writes: | > sed is the way. | | No, it's not. Try head -1 | sed 's/.../.../'; cat. Okay, results below. | On this | machine, sed is more than 12 times slower than cat. results: Script started [y.tmp] at Tue Oct 23 23:03:14 1990 $ ls -l x.tmp -rw-r--r-- 1 davidsen users 143405 Oct 23 23:01 x.tmp $ time cat x.tmp > /dev/null real 0m0.50s user 0m0.00s sys 0m0.36s $ time sed '1s/foo/bar/' x.tmp > /dev/null real 0m2.20s user 0m1.42s sys 0m0.40s $ time { head -1; sed 's/foo/bar/'; cat; } < x.tmp > /dev/null real 0m3.16s user 0m1.86s sys 0m0.70s $ exit Script ended [y.tmp] at Tue Oct 23 23:05:28 1990 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. Other points: Yes, this was ksh, so the time reported is for all processes. /bin/time would not do as well unless you started a subshell. Your 12:1 slower surprised the hell out of me, but you are definitely in the right order of magnitude, perhaps even being a little nice to sed. I really would have expected sed to just bypass the stuff after line 1. -- bill davidsen - davidsen@sixhub.uucp (uunet!crdgw1!sixhub!davidsen) sysop *IX BBS and Public Access UNIX moderator of comp.binaries.ibm.pc and 80386 mailing list "Stupidity, like virtue, is its own reward" -me