| Note that Rust and Go programs differ in a seemingly insignificant, but actually important detail. Rust does this next_dist = std::cmp::min(
dist_if_substitute,
std::cmp::min(dist_if_insert, dist_if_delete),
);
Go does this nextDist = min(
distIfDelete,
min(distIfInsert, distIfSubstitute)
)
The order of minimums is important for this dynamic programming loop. If I change Rust version to take minimums in the same order (swapping substitute and delete), runtime drops from 1.878696288 to 1.579639363.I haven't investigated this, but I would guess that this is the same effect I've observed in * https://matklad.github.io/2017/03/12/min-of-three.html * https://matklad.github.io/2017/03/18/min-of-three-part-2.htm... (reposting my comment from reddit, as it's a rather unexpected observation) |