Remix.run Logo
mcdeltat 9 hours ago

You have to be extremely careful with benchmarks like these. It's very easy to measure and conclude different things. In this case, it really only measures the compiler's ability to optimise the `for` loop construct - nothing else. It doesn't say anything much about the languages' general "speed", whatever that means (which is generally the implication with tests like this).

Some points to consider:

- `for` is not how you'd write an optimised loop in all languages.

- Be VERY suspicious of microbenchmarks on C, C++, and similar - the compilers are smarter than you think and you won't get the code you wrote.

- Languages do arrays differently - added memory effects on performance.

- Languages do numbers differently.

- Summing and modulo is somewhat contrived example. Modulo is one of the slower instructions out there.