$ time ./wc.py wc.pl wc.py large.txt
21 58 494 wc.pl
25 96 698 wc.py
382230 1290003 11930691 large.txt
382276 1290157 11931883 total
real 0m7.922s
user 0m7.218s
sys 0m0.124s
$ time ./wc.pl wc.pl wc.py large.txt
21 58 494 wc.pl
25 96 698 wc.py
382230 1290003 11930691 large.txt
382276 1290157 11931883 total
real 0m4.484s
user 0m4.186s
sys 0m0.093s
####
#!/usr/bin/python
import sys
files = map(lambda f: open(f), sys.argv[1:]) or [sys.stdin]
Twords = Tlines = Tchars = 0
for file in files:
words = lines = chars = 0
for line in file.xreadlines():
lines += 1
words += len(line.split())
chars += len(line)
print "%7d %7d %7d %s" % (lines, words, chars, file.name)
Twords += words
Tlines += lines
Tchars += chars
if len(sys.argv) > 2:
print "%7d %7d %7d total" % (Tlines, Twords, Tchars)
##
##
$ time ./wc.py wc.pl wc.py large.txt
21 58 494 wc.pl
17 74 518 wc.py
382230 1290003 11930691 large.txt
382268 1290135 11931703 total
real 0m6.157s
user 0m6.046s
sys 0m0.124s