kwik way?

Devin Teske dteske at vicor.com
Wed May 18 18:20:06 UTC 2011


> -----Original Message-----
> From: owner-freebsd-questions at freebsd.org [mailto:owner-freebsd-
> questions at 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.
_____________


More information about the freebsd-questions mailing list