kwik way?

Devin Teske dteske at vicor.com
Wed May 18 18:36:23 UTC 2011


> -----Original Message-----
> From: owner-freebsd-questions at freebsd.org [mailto:owner-freebsd-
> questions at freebsd.org] On Behalf Of Devin Teske
> Sent: Wednesday, May 18, 2011 11:19 AM
> To: 'Gary Kline'; 'FreeBSD Mailing List'
> Subject: RE: kwik way?
> 
> > -----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

In case you were thinking of either awk or perl, I'd recommend against those
given the following results:

$ time sh -c "awk '{gsub(/\t/,\" \");print}' < foo > bar"
real    0m2.769s
user    0m1.498s
sys     0m0.140s
$ md5 bar
MD5 (bar) = f0187bcbc37cd6d84c6f5cadc6443843

$ time sh -c "perl -pe 'tr/\t/ /' < foo > bar"
real    0m0.565s
user    0m0.277s
sys     0m0.137s
$ 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.
> _____________
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"

_____________

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