Crates.io | wc-rs |
lib.rs | wc-rs |
version | 0.1.2 |
source | src |
created_at | 2019-10-11 18:04:12.412551 |
updated_at | 2019-10-11 20:02:44.302473 |
description | A faster port of the unix wc |
homepage | https://palash25.netlify.com/post/writing-technical-content/ |
repository | https://github.com/palash25/wc-rs |
max_upload_size | |
id | 171740 |
size | 15,964 |
The good old unix tool rewritten in Rust.
I wanted to learn Rust and this seemed like a small and simple enough project to get started with.
To my surprise this naive implementation turned out to be faster than the original C implementation of wc
, take a look at some numbers. This is my first rust project so it might contain some bad code, please raise an issue if you find any room for improvment within the codebase.
cargo install wc-rs
git clone https://github.com/palash25/wc-rs.git
cd wc-rs/
cargo build --release
Same as the standard wc
command that is shipped with every linux distro.
$ wc-rs --help
USAGE:
wc-rs [FLAGS] [FILE]...
FLAGS:
-m, --chars prints the character counts
-h, --help Prints help information
-l, --lines prints the newline counts
-V, --version Prints version information
-w, --words print the words counts
ARGS:
<FILE>... file path(s) to run wc-rs on
$ \time wc-rs small-file-*
48414 81402 556859 small-file-1
48414 81402 556859 small-file-2
48414 81402 556859 small-file-3
145242 244206 1670577 total
real 0:00.05 user 0.05 sys 0.00
$ \time ./target/release/wc-rs small-file-*
48414 81402 556859 small-file-1
48414 81402 556859 small-file-2
48414 81402 556859 small-file-3
145242 244206 1670577 total
real 0:00.02 user 0.00 sys 0.01
$ wc-rs small-file-* | pv
48414 81402 556859 small-file-1
48414 81402 556859 small-file-2
48414 81402 556859 small-file-3
145242 244206 1670577 total
159 B 0:00:00 [ 3.1KiB/s] [ <=> ]
$ ./target/release/wc-rs small-file-* | pv
48414 81402 556859 small-file-1
48414 81402 556859 small-file-2
48414 81402 556859 small-file-3
145242 244206 1670577 total
186 B 0:00:00 [9.57KiB/s] [ <=> ]
$ \time wc-rs big-file-*
2091965 3549748 24604624 big-file-1
2091965 3549748 24604624 big-file-2
4183930 7099496 49209248 total
real 0:01.14 user 1.11 sys 0.02
$ \time ./target/release/wc-rs big-file-*
2091965 3549748 24604624 big-file-1
2091965 3549748 24604624 big-file-2
4183930 7099496 49209248 total
real 0:00.49 user 0.36 sys 0.12
$ wc-rs big-file-* | pv
2091965 3549748 24604624 big-file-1
2091965 3549748 24604624 big-file-2
4183930 7099496 49209248 total
121 B 0:00:01 [ 101 B/s] [ <=> ]
$ ./target/release/wc-rs big-file-* | pv
2091965 3549748 24604624 big-file-1
2091965 3549748 24604624 big-file-2
4183930 7099496 49209248 total
148 B 0:00:00 [ 315 B/s] [ <=> ]
$ \time wc-rs bigger-file-*
10048406 17328448 124739305 bigger-file-1
10446226 18017383 129746037 bigger-file-2
20494632 35345831 254485342 total
real 0:05.73 user 5.66 sys 0.05
$ \time ./target/release/wc-rs bigger-file-*
10048406 17328448 124739305 bigger-file-1
10446226 18017383 129746037 bigger-file-2
20494632 35345831 254485342 total
real 0:02.20 user 1.64 sys 0.55
wc-rs big-file-* | pv
10048406 17328448 124739305 bigger-file-1
10446226 18017383 129746037 bigger-file-2
20494632 35345831 254485342 total
130 B 0:00:05 [22.5 B/s] [ <=> ]
./target/release/wc-rs bigger-file-* | pv
10048406 17328448 124739305 bigger-file-1
10446226 18017383 129746037 bigger-file-2
20494632 35345831 254485342 total
157 B 0:00:02 [69.5 B/s] [ <=> ]
This is where things start to slow down a little. This file has double the number of characters than the previous one and almost double the size (~250MB)
$ \time -p wc-rs big-and-chonky.txt
10048951 31711680 274285495 big-and-chonky.txt
real 4.72 user 4.67 sys 0.04
$ \time -p ./target/release/wc-rs big-and-chonky.txt
10048951 31711680 274285495 big-and-chonky.txt
real 1.89 user 1.36 sys 0.53
$ wc-rs big-and-chonky.txt | pv
10048951 31711680 274285495 big-and-chonky.txt
46 B 0:00:04 [9.81 B/s] [ <=> ]
$ ./target/release/wc-rs big-and-chonky.txt | pv
10048951 31711680 274285495 big-and-chonky.txt
55 B 0:00:01 [29.2 B/s] [ <=> ]