I have sometimes mentioned here my attempts to reimplement a solution to the Project Euler problem #256 "Tatami-Free Rooms" in Rust. The original being in C and written by E.J.Olsen.
Today I have arrived at a version that is faster than the original C both on my x86_64 PC and on the ARM of a Rasperry Pi 3B.
A simple makefile builds and times them:
On the Pi 3B
pi@debian-buster-64:~/tatami-rust $ make run
gcc -Wall -O3 -o prune prune.c -march=native -mtune=native
gcc -Wall -O3 -o limited limited.c -march=native -mtune=native
RUSTFLAGS="-C opt-level=3 -C debuginfo=0 -C target-cpu=native" cargo build --release --features=use_i32
Compiling tatami_rust v0.1.0 (/home/pi/tatami-rust)
Finished release [optimized] target(s) in 3.56s
time ./limited
T(85765680)=200
4.34user 0.00system 0:04.36elapsed 99%CPU (0avgtext+0avgdata 1220maxresident)k
0inputs+0outputs (0major+69minor)pagefaults 0swaps
time ./prune
Pr(1300)=10657
T(85765680)=200
4.14user 0.00system 0:04.14elapsed 99%CPU (0avgtext+0avgdata 1164maxresident)k
0inputs+0outputs (0major+68minor)pagefaults 0swaps
time ./target/release/tatami_rust 200
Using 32 bit integers.
PNUM = 1300
FNUM = 10
SMAX = 100000000
T(85765680)=200
4.04user 0.00system 0:04.04elapsed 99%CPU (0avgtext+0avgdata 1528maxresident)k
0inputs+0outputs (0major+85minor)pagefaults 0swaps
On the x86_64 PC:
zicog@monster:/mnt/c/Users/zicog/tatami-rust$ make run
gcc -Wall -O3 -o prune prune.c -march=native -mtune=native
gcc -Wall -O3 -o limited limited.c -march=native -mtune=native
RUSTFLAGS="-C opt-level=3 -C debuginfo=0 -C target-cpu=native" cargo build --release --features=use_i32
Compiling libc v0.2.66
Compiling tatami_rust v0.1.0 (/mnt/c/Users/zicog/tatami-rust)
Compiling time v0.1.42
Finished release [optimized] target(s) in 6.02s
time ./limited
T(85765680)=200
0.90user 0.01system 0:00.92elapsed 100%CPU (0avgtext+0avgdata 584maxresident)k
0inputs+0outputs (0major+175minor)pagefaults 0swaps
time ./prune
Pr(1300)=10657
T(85765680)=200
0.81user 0.00system 0:00.83elapsed 96%CPU (0avgtext+0avgdata 584maxresident)k
0inputs+0outputs (0major+177minor)pagefaults 0swaps
time ./target/release/tatami_rust 200
Using 32 bit integers.
PNUM = 1300
FNUM = 10
SMAX = 100000000
T(85765680)=200
0.60user 0.00system 0:00.64elapsed 94%CPU (0avgtext+0avgdata 876maxresident)k
0inputs+0outputs (0major+257minor)pagefaults 0swaps
All code is here if anyone wants to play along: https://github.com/ZiCog/tatami-rust
Next up, somebody has written a multi-threaded version that is much faster. Anyone know the best way to queue work into a thread pool in Rust?
Thanks to all who have helped with this along the way.
Merry Christmas.