Modern fortran is surpisingly pleasant to write. The last time optimisation came up, I tried the author's problem - multiplying two 4096x4096 matrices - in numpy, FORTRAN and Rust, on a standard laptop. Supposedly it took 9 hours in naive Python (I didn't try). Results were: Python3 (numpy 1.18.4) 1.3s FORTRAN (gfortran 9.3.0) 6.0s Rust (1.43.1, debug) >60s Rust (1.43.1, release) 4.0s What surprised me is that python…
> every single way I tried had "gotchas" and utterly astonishing behaviour in it
As someone who doesn't know much about Rust (or FORTRAN for that matter), what kinds of gotchas? I'd expect numeric code like this to be quite straightforward, as it presumably doesn't lean heavily on memory-management cleverness in the language, or anything like that.
[0] https://en.wikipedia.org/wiki/Strassen_algorithm
edit For clarity, I made a table of your data. Seems surprising that Rust outperformed FORTRAN.
┌──────────┬─────────────────┬──────┐
│ Language │ Detail │ Time │
├──────────┼─────────────────┼──────┤
│ Python3 │ numpy 1.18.4 │ 1.3s │
│ FORTRAN │ gfortran 9.3.0 │ 6.0s │
│ Rust │ 1.43.1, debug │ >60s │
│ Rust │ 1.43.1, release │ 4.0s │
└──────────┴─────────────────┴──────┘