As we discussed on the Nim forum¹, the Nim programs could definitely be improved a lot. elcritch did some optimization and managed to make Nim's time roughly equal to Rust.
That speedup is accomplished by using a third-party LRU implementation. I can also speed up the Rust version by 30% by plugging in https://lib.rs/crates/lru.
(The thread points out that the Nim version uses a doubly-linked list from the standard library while you'd need unsafe in Rust, and the lru crate does indeed use unsafe. So take that into account.)
Unsafe is part of the rust language. Theres nothing wrong with using it if you know what you’re doing. The value of unsafe is that it boxes your unsafe code - so you can direct extra care to those functions when writing, reviewing and auditing. (As opposed to C where memory corruption could happen anywhere, so you need to be careful everywhere.)
I could imagine a separate language on the programming languages shootout which is “safe rust”. It’d be interesting how the best unsafe and the best safe programs compare in speed and size.
If you believe Rust zero cost abstraction - being safe doesn't mean it has to be compared to safe languages because Rust and C can translate into same assembler code. But in Rust the compiler gives you more guarantees.
I would say that a proper way to rephrase it would be to use idiomatic code vs unidiomatic. If you start using any high-level language in a non intended fashion (writing non idiomatic code) probably most of them would be faster.
Note that using the third party LRU makes the Nim version faster than the Rust one by 15%. Fixing the Deque/Table Nim version results in the same times as the Rust Dec/HashMap one.
I think people may not know or may not remember that ~6 years ago or so there was a fairly significant effort to increase rust's position in the benchmarks. I remember it coming up a lot on /r/rust when the language had stabilized. "C or C++ is first place? Isn't Rust supposed to be fast?" etc.
I assume nim has gotten a lot less attention in these benchmarks and there's probably huge wins available to it.
¹ https://forum.nim-lang.org/t/8868