DEV Community

Discussion on: The Great Prime Number Challenge: Which Programming Language is the Fastest?

Collapse
 
marcomalva profile image
marcomalva

Rust is so slow b/c it default to be build on debug mode.
On my system (Intel i5-7600K/Fedora 37/rustc 1.69,go 1.20) the differences are very clear:

  • default, debug version takes 23.3s, pretty much what you have
  • with -C opt-level=1 it goes down to 4.1s
  • and with -C opt-level=2 it goes down to 4.0s
  • and with -C opt-level=1 -C target-cpu=native it goes down to 3.7s
  • and with -C opt-level=2 -C target-cpu=native it goes down to 4.1s.

Best performance with rustc -C opt-level=1 -C target-cpu=native primes.rs

For Go you need to switch to integer type uint32.
On my system that brought the time down from 13s (similar to yours) to 3.6s.