4 ms·
No, it's not faster. They are comparing a Go version that does not do character decoding (which is necessary for correctly counting the number of words under th
by danieldk 7y ago
No, it's not faster. They are comparing a Go version that does not do character decoding (which is necessary for correctly counting the number of words under the presence of non-ASCII punctuation) to a C version that does decode characters (and matches them against a larger character set with iswspace).
This can be easily shown, by counting words and lines using wc separately. Word counting decodes characters (to find non-ASCII whitespace that may separate words), whereas line counting just looks for ASCII line separators:
$ time wc -w wiki-large.txt
17794000 wiki-large.txt
wc -w wiki-large.txt 0.48s user 0.02s system 99% cpu 0.496 total
$ time wc -l wiki-large.txt
854100 wiki-large.txt
wc -l wiki-large.txt 0.02s user 0.01s system 99% cpu 0.034 total
So, without character decoding, looking at every byte is ~15 times faster. So, if you'd compile wc without multibyte character support (which would be a fair comparison), it would probably beat Go without any parallelization.
- ajeetdsouza 7y agoThis is not true, see my comment here: https://news.ycombinator.com/edit?id=21587907 https://news.ycombinator.com/edit?id=21587907
- danieldk 7y agoTake the Darwin version linked from your site. Run perf record wc thefile.txt. Then run perf report and you will see iswspace in the call graph. As I show in [1], removing this call and replacing it by a character match, gives a speedup of almost 2x. [1] https://news.ycombinator.com/item?id=21592089 https://news.ycombinator.com/item?id=21592089