6.2.0.2
Counting Words
For this homework set, you will design a Rust version of Unix’s wc.
The objective of this homework is to deepen your knowledge of Rust’s I/O system and its iterators.
Deadline Friday 30 January NOON.
wc
Your version of wc consumes a file name on the command line and produces
a single line with three numbers followed by the file name:
$ wc 1.scrbl |
73 399 2776 1.scrbl |
$ wc 2.scrbl |
73 392 2722 2.scrbl |
The first number is the number of lines in the specified file, the second
the number of "words", and the third the number of bytes.
Following historical convention, you may assume that a word as a maximal string of characters delimited by <space>, <tab>, or <newline>. You may also assume ASCII input.
Compare the time that your version takes for "counting" the
bible to the one that the built-in version
of wc:
$ /usr/bin/time wc bible-plain-text.txt |
92870 969905 5371778 bible-plain-text.txt |
0.03 real 0.03 user 0.00 sys |
That is, on a simple Mac notebook, wc takes .03s to read and count the
entire ASCII text of the bible. Keep the difference within an order of
magnitude.