3 ms·
C++ was probably compiled without optimizations. In a compiled binary there won't even be any calculations done - see for yourself https://godbolt.org/z/Mhhzhdr
by somerando7 3y ago
C++ was probably compiled without optimizations. In a compiled binary there won't even be any calculations done - see for yourself https://godbolt.org/z/Mhhzhdr7c https://godbolt.org/z/Mhhzhdr7c
- anandnair 3y agoI did it, and now c++ is slightly faster than Rust :)
- DemocracyFTW2 3y agoover here we never say more faster, instead we say fasterer or simply fasterrr
- anandnair 3y agooops, edited
- Someone 3y agoBut likely not at calculating that sum (which, nitpicking, isn’t “calculating the sum of 1M numbers”, but “calculating the sum of integers 1 through 1,000,000”), but at printing a constant. It’s possible the C library you used is faster at converting this particular integer to a string (performance will vary between different ones, and not necessarily with one being always faster than the other) and writing it than rust’s one, but also possible that the C compiler did the string conversion at compile-time, too, and compiled a call to puts (if you printed a newline at the end of your string)