Date: Wed, 18 May 2011 11:19:21 -0700 From: "Devin Teske" <dteske@vicor.com> To: "'Gary Kline'" <kline@thought.org>, "'FreeBSD Mailing List'" <freebsd-questions@FreeBSD.ORG> Subject: RE: kwik way? Message-ID: <000801cc1588$1cf81e20$56e85a60$@vicor.com> In-Reply-To: <20110518174141.GA62977@thought.org> References: <20110518174141.GA62977@thought.org>
next in thread | previous in thread | raw e-mail | index | archive | help
> -----Original Message----- > From: owner-freebsd-questions@freebsd.org [mailto:owner-freebsd- > questions@freebsd.org] On Behalf Of Gary Kline > Sent: Wednesday, May 18, 2011 10:42 AM > To: FreeBSD Mailing List > Subject: kwik way? > > should i use tr or sed to turn "\t" into " "? --i.e., tabs into spaces. Depends on how you do it in sed. The y/// operator is faster than s/// when transliterating a single character globally. If you use y/// instead of s///, then sed performance should be on-par with tr. Below are some performance metrics involving a 100,000 line contrived text file containing 1M tabs and 1.8M spaces: $ wc -l foo 100000 foo $ du -h foo 2.8M foo $ file foo foo: ASCII text $ time sh -c "sed -e 's/ / /g' < foo > bar" real 0m2.479s user 0m1.047s sys 0m0.105s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 $ time sh -c "tr '\t' ' ' < foo > bar" real 0m0.261s user 0m0.120s sys 0m0.026s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 $ time sh -c "sed -e 'y/ / /' < foo > bar" real 0m0.261s user 0m0.116s sys 0m0.087s $ md5 bar MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843 -- Devin _____________ The information contained in this message is proprietary and/or confidential. If you are not the intended recipient, please: (i) delete the message and all copies; (ii) do not disclose, distribute or use the message in any manner; and (iii) notify the sender immediately. In addition, please be aware that any message addressed to our domain is subject to archiving and review by persons other than the intended recipient. Thank you. _____________
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000801cc1588$1cf81e20$56e85a60$>