We have a file with a list of space-separated words on each line, as produced by generate_example.py
.
The solution program should output the words that appear at least once on each line, sorted.
Three implementations are compared, one in python and two in rust.
Results:
# Generate the example file
$ python generate_example.py > example.txt
# Compile the rust program with the release profile
$ cargo fmt && cargo clippy && cargo build --release
$ cp target/release/intersection intersection
# Compile the rust program with the release profile and the ahash feature
$ cargo fmt && cargo clippy && cargo build --release --features ahash
$ cp target/release/intersection intersection-ahash
# Time the python execution
$ \time -f "%U s" python intersection.py < example.txt
knight marines pat pg porter reed twain
1.07 s
# Time the rust execution
$ \time -f "%U s" target/release/intersection < example.txt
knight marines pat pg porter reed twain
1.17 s
# Time the rust execution
$ \time -f "%U s" target/release/intersection-ahash < example.txt
knight marines pat pg porter reed twain
0.67 s