This is my late addition to a trend form late 2019, about trying to write a simple wc clone in a few lines of code and trying to beat it's performance

schicho / vwc

submited by
Style Pass
2021-06-13 23:00:04

This is my late addition to a trend form late 2019, about trying to write a simple wc clone in a few lines of code and trying to beat it's performance.

The original article, which started the trend, rewrote it in Haskell and my implementation is based on a program written in Go by Ajeet D'Souza

To be exact, as V's syntax is by desgin very close to Go, I mostly just rewrote Ajeet D'Souza's Go code in V. The original source code can be found here.

I am going to compare the results using GNU time, as done by others in their articles. I am comparing the performance on parsing a 100 MB and 1 GB text file, with ascii characters only.

For better comparison with the Go code, I will not rely on the stats given in the original article, but will compile the Go code myself using Go 1.16.

The single threaded code reads into the buffer and then counts the words in that buffer, keeping track of wether we just started a new word previously or not. D'Souza's article goes into this in a lot more detail under the section 'Splitting the input'. The code can be directly transfered from Go to V with minor adjustments. Only difference is, instead of relying on system calls to get the file size, I decided to count all the bytes manually in the process.

Leave a Comment
Related Posts