There is currently a discussion going on on Hacker News about the Rust vs Num Programming Language Benchmarks (https://programming-language-benchmarks.vercel.app/nim-vs-rust) that were recently discussed in this forum. The discussion is here:
https://news.ycombinator.com/item?id=30243219
I'm seeing a lot of wild, probably inaccurate assertions made about Rust being _always faster than nim, that nim has a runtime and therefore _is slower than C or Rust by definition, or that nim can only be compared with a language like go, not with the likes of C and Rust, etc. @xigoi already replied saying that the benchmarks are not very accurate, but people seem to believe that the only reason nim was improved was because it used an external LRU library.
I think it might be a good idea for others to give their 2 cents in that thread. Otherwise people will leave that discussion with the impression that nim is not a good alternative for programs that require high performance.
This benchmark repo is much more popular (second in Google Search), and showing Nim is quite fast https://github.com/kostya/benchmarks
The benchmark referred in this topic, seems to be less popular, and so the code is less reviewed and not very well optimised.
Well I believe so, but obviously some people in the Hacker News thread do not think so. If a person see a benchmark showing Nim is slower, and also knows that Nim has GC, he/she might think Nim has a heavy runtime and thus cannot be faster.
Someone in the thread said he has 30 years experience in programming, and the only new lang which is really close to C in speed is Rust. I don't know if this is really true, but I think the impression must be from some benchmarks. If Nim claims that it is efficient, then giving an official benchmark is a good idea.
Is it that hard to beat rust in performance, that you want to give up entirely?
No, what's hard is making sure every benchmark site has optimal Nim code that is fair for Nim.
There are plenty of other sites doing similar comparisons and doing them well, so removing the poor comparisons could be effective.
In Discord we were joking around that we could quickly set up many benchmark sites which purport to show Nim being much better than other languages, where we just have all other languages having really poorly implemented algorithms. There comes a point where these sites are just propaganda and there isn't enough people wanting to improve their language's algorithms.
I have an i5-8250U.
The rust version takes ~2 seconds (cargo build --release).
The nim version takes ~1.5 seconds (nim c --mm:orc -d:danger).
The website states to use a Xeon Platinum 8171M 2.60GHz.
The rust version takes ~2 seconds.
The nim version takes ~3.7 seconds.
Am I building the rust version wrong on my PC? Has somebody else tried these benchmarks?
I had a similar comment thread on Hacker News post on Zig. The Zig creator claimed that "no other modern languages matched its low memory footprint". Fairly ridiculous claim if you ask me given not just Nim, but Rust, D, heck even Go, Vala, C++20, and Swift. Unfortunately many developers without experience in writing software concerned with memory footprint will believe it (and not realize it's also not a memory safe language). In real usage there's almost always tradeoffs between halfway decent languages.
Eventually I ran a semi-random benchmark that seemed to have a decent memory usage overhead (https://github.com/kostya/benchmarks/tree/master/brainfuck). The Nim code was decently written. I had to fix the Zig code (it's pre-1.0 so fair enough), but it was annoying to figure out how to convert i32 to the u64 indexes. Otherwise both implementations were almost identical along with the Rust and Go versions.
Here's the results as I posted to HN:
Curiosity got to me, perhaps Zig had improved significantly. So I compared the first benchmark I found (kostya/benchmarks/bf) with Zig with Nim. For the smaller input (bench.b) Zig did run with ~22% less RAM (about 20kB less). However, for the larger input (mandel.b) Nim+ARC used ~33% less RAM in safe mode: Nim 2.163mb -d:release; Zig 2.884mb -O ReleaseSafe; Zig 2.687mb -O ReleaseFast. The Nim requires 0.5mb less ram and the code is ~40% shorter. I don't have time to try out the Rust or Go versions though.
It was interesting too that changing Nim to use int32's or {.packed.} structs actually increased the memory usage. Nim was a bit slower unless compiled with -d:danger but I was a bit surprised how well Nim's seq and iterator did when combined with ARC compared to a manual memory management. I'd expected equal memory usage with larger brainkfuck programs, not 30% less. I am curious how the Rust & Go versions compare.
If Nim claims that it is efficient, then giving an official benchmark is a good idea.