News for hackers. Stuff that matters.
Re:Ask HN: Why is Rust faster than C++ for calculating the s... by anandnair on Saturday April 01, 2023 @04:29AM (#35398423)
I did it, and now c++ is slightly more faster than Rust :)
Re:Ask HN: Why is Rust faster than C++ for calculating the s... by DemocracyFTW2 on Saturday April 01, 2023 @05:24AM (#35398695)
over here we never say more faster, instead we say fasterer or simply fasterrr
Re:Ask HN: Why is Rust faster than C++ for calculating the s... by anandnair on Saturday April 01, 2023 @05:25AM (#35398707)
oops, edited
Re:Ask HN: Why is Rust faster than C++ for calculating the s... by Someone on Saturday April 01, 2023 @02:55PM (#35402964)
But 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)