Third: if done in a 10 lines in python it is around 30% faster than the C++ version and 2x faster than the perl version.
Here is my reference Python version that also counts the words in the same non-code golf kind of way:
import sys
from collections import defaultdict
def wc(path):
d = defaultdict(int)
with open(path) as f:
for line in f:
for w in line.split():
d[w] += 1
return sum(d.values())
if __name__=='__main__':
path = sys.argv[1]
print(path, ':', wc(path))
First, this can be done with one line in Python.
Second, it's almost a page of C++.
Third: if done in a 10 lines in python it is around 30% faster than the C++ version and 2x faster than the perl version.
Here is my reference Python version that also counts the words in the same non-code golf kind of way:
EDIT: They are counting new lines correctly.